ProcessStart As Current Logged In User - Need Assistance
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: ProcessStart As Current Logged In User - Need Assistance

  1. #1
    Join Date
    Jun 2014
    Posts
    3

    Exclamation ProcessStart As Current Logged In User - Need Assistance

    I am working on what I would have thought was a simple Windows Forms Application. I am using .NET 4.5 & Visual Studio 2013. My idea was to have a "launcher" to open the various applications that gets used.

    Our company uses a multitude of custom applications; quoting, application to modify "assemblies" in quoting, measurement tool, etc.

    I am curious as to how I could run our permission based applications using Process.Start. It would need to support the domain name, as well as the user. Can this be done via the current logged in user as oppose to the system account? I need some guidance please.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,243

    Re: ProcessStart As Current Logged In User - Need Assistance

    If you have a Windows form and use Process.Start, the application being launched will normally be run in the context of the user running the Windows form application.

    If the logged on user has permissions to run the app then there is no problem; however, if the user doesn't have permission, Process.Start also has an overloaded method that allows you to pass in the user name and password to run an app under the context of that user.

    Unfortunately, that means your app would have to supply the correct un and pw for the app (and that would be a bit of a security hole).

  3. #3
    Join Date
    Jun 2014
    Posts
    3

    Re: ProcessStart As Current Logged In User - Need Assistance

    Quote Originally Posted by Arjay View Post
    If you have a Windows form and use Process.Start, the application being launched will normally be run in the context of the user running the Windows form application.

    If the logged on user has permissions to run the app then there is no problem; however, if the user doesn't have permission, Process.Start also has an overloaded method that allows you to pass in the user name and password to run an app under the context of that user.

    Unfortunately, that means your app would have to supply the correct un and pw for the app (and that would be a bit of a security hole).
    Let me elaborate what I am trying to achieve. An average user in office uses roughly 6 different custom applications per day, not particularly at the same time, but it would be common to close one that won't be needed for an hour or so, then re-open it as needed. There are also a few server shares containing Excel Spreadsheets that are collaborated on. My idea was to create a "screen menu" that is not obtrusive, that would basically launch the different applications we use, and open common spreadsheets that are opened often.

    Here is the problem I face, our applications checks for {Domain}\{Username} to launch our applications. Using Process.Start, the user is NTAuthority\System. Back to my original question, am I able to 'get' the current logged in user domain/username and use those for Process.Start function?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,243

    Re: ProcessStart As Current Logged In User - Need Assistance

    I understand what you are after. How is the screen menu app getting launched? Does the user launch it? Or is it being run on machine startup before the user logs in (such as through an HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key)?

  5. #5
    Join Date
    Jun 2014
    Posts
    3

    Re: ProcessStart As Current Logged In User - Need Assistance

    Quote Originally Posted by Arjay View Post
    I understand what you are after. How is the screen menu app getting launched? Does the user launch it? Or is it being run on machine startup before the user logs in (such as through an HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run key)?

    The application would get launched manually...for now. I added a message box to display the user...
    MessageBox.Show(startInfo.UserName);
    This does show the correct domain and username, however the application fails to load.

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,243

    Re: ProcessStart As Current Logged In User - Need Assistance

    I misread your reply as it didn't start under the user's context. So I wrote a test app to start notepad.

    Code:
    class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Press [ENTER] to start notepad.");
                Console.ReadLine();
    
                Process.Start(@"C:\Windows\System32\notepad.exe");
    
                Console.WriteLine("Open task manager to see which user notepad is running under.");
                Console.ReadLine();
            }
        }
    Then I reread your text and noticed it did start under the correct context.

    Well, in that case something else is wrong. Perhaps there are additional command line parameters that you need to pass to the apps? If a user normally launches the app with a desktop shortcut, look at the properties of the shortcut.

    Lastly, the apps that you are trying to launch are installed locally, right? If not, there are restrictions to launching .net apps over the network (assuming what you are attempting to launch are .net apps).

  7. #7
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: ProcessStart As Current Logged In User - Need Assistance

    Might want to tell us the OS that has the problem as well.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center