Results 1 to 13 of 13

Thread: [RESOLVED] "Code to check if there is another instance of program running works on XP but not o

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    16

    Resolved [RESOLVED] "Code to check if there is another instance of program running works on XP but not o

    Hi All i am facing an issue with Vista.
    I have logged in as administrator also but the following line is generating an exception which was working correctly earlier in XP & 2000

    " (Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) "

    I know its due to the security features added by Vista because when I disable UAC in Vista its working perfectly.

    Can anybody help me in this case

    I am pasting the whole code


    Public Const gsResourceNamespace As String = "NBXCAS"

    If gbMultipleAppInstances(gsResourceNamespace) Then
    psErrorMessage = "Not allowed to have multiple instances of: " & gsApplicationDisplayName
    Call mDisplayStartupError(psErrorMessage, MsgBoxStyle.ApplicationModal + MsgBoxStyle.Exclamation)
    End
    End If

    Public Function gbMultipleAppInstances(ByVal vsWindowCaption As String) As Boolean

    Return (UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0)

    End Function

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: "Code to check if there is another instance of program running works on XP but not o

    What's wrong with using App.PrevInstance?

  3. #3
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: "Code to check if there is another instance of program running works on XP but not o

    BTW: if this is VB.NET you are in the wrong forum...

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    16

    Re: "Code to check if there is another instance of program running works on XP but not o

    Thanks Randem,

    But didnt got good response in a .Net forum so posted here if anybody know any solution ?

    Regards,
    Pragya

  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: "Code to check if there is another instance of program running works on XP but not o

    I don't do .NET (Yet) but searching the Internet I came up with this:
    Code:
    Imports System.Diagnostics
    
    Dim aModuleName As String = Diagnostics.Process.GetCurrentProcess.MainModule.ModuleName
    
    Dim aProcName As String = System.IO.Path.GetFileNameWithoutExtension(aModuleName)
    
        If Process.GetProcessesByName(aProcName).Length > 1 Then
            Application.Exit()
        End If

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    16

    Re: "Code to check if there is another instance of program running works on XP but not o

    Hi Randem ,

    Thanks for the code ... I will give it a try once & let you know
    do you work on Install Shield too ?
    As your title says "Installation Specialist" I am also working in this field but i am just a beginner If I am having some install shield related doubts can I ask you that also ?

    Regards,
    Pragya

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: "Code to check if there is another instance of program running works on XP but no

    I can only give you theory about Install Shield, I work with ********** (Inno Script) and Inno Setup.

    Well, as a beginner you may want to read this Installation Problems
    Last edited by randem; Oct 5th, 2007 at 02:49 AM.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    16

    Re: "Code to check if there is another instance of program running works on XP but not o

    Thanks Randem,

    I got the solution of my problem in a different way
    Actually in Vista we need more privlidges to run this statement
    so i included a manifest file and the same code is working
    I reffered to following link
    http://community.bartdesmet.net/blog...ng-mt.exe.aspx

    Thanks,
    Pragya

    Thanks,
    Pragya

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: "Code to check if there is another instance of program running works on XP but not o

    Actually that is a bad way to solve the issue and a security risk. You should never just use an xml file to require the full program be run as an admin.

    The best way is to redesign the app depending on the amount of admin actions. If you only have a few then split the admin stuff to another exe or an activex dll etc to create another process that can be elevated. Then other other way is to recod the apps admin tasks properly so they dont need admin permissions. Like reading/writting to the registry should no longer really be needed/done. So using an xml file for your reg settings is preferred and no admin perms needed.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: "Code to check if there is another instance of program running works on XP but not o

    As RobDog888 stated, giving more privileges is not the answer. You are suppose to give less privileges to avoid other situations. If your program REQUIRES admin privileges to run, it should be a utility not a application...

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    16

    Re: "Code to check if there is another instance of program running works on XP but not o

    Thanks for all your suggestions I will keep all that in my mind & try to reorganize my application ...

    Regards
    Pragya

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: "Code to check if there is another instance of program running works on XP but not o

    Quote Originally Posted by pragya
    But didnt got good response in a .Net forum so posted here if anybody know any solution ?
    1. That is not relevant. .NET related questions belong in .NET - Classic VB questions belong in Classic VB. Period.

    2. I looked....you did not post this question in the .NET section, otherwise, I would have taken this post, and merged it with the one in .NET

    Moved to VB.NET

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    16

    Re: "Code to check if there is another instance of program running works on XP but not o

    Hack,

    I posted it on VB .Net forum I am not able to attach that link
    Thanks for you suggestion I will keep this in mind

    Regards
    Pragya
    Last edited by pragya; Oct 10th, 2007 at 01:28 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width