Jump to content

How force system started process to run as a specific user?


iAmNewbe
 Share

Recommended Posts

I have a exe I created that is started by a SYSTEM process. I need this to run as a specific user. How do I force this exe when it is started to change it's user?

I do not have control over the starting of the program, I can't send commands or anything to it before it is started.

Link to comment
Share on other sites

Something like this at the top of the script:

If Not StringInStr($CmdLineRaw, " /user") Then
    RunAs("Username", @ComputerName, "Password", 0, $CmdLineRaw & " /user", @WorkingDir)
    Exit
EndIf

There are probably better ways to do it than that, but basically check at the beginning of your script whether you are running as the user like you want, and if not then start the process yourself and then exit.

Link to comment
Share on other sites

I have tried something like this, using that code but it doesn't work. Once the program is running it is under SYSTEM user and nothing I have been able to do has changed this or any of it's spawned applications. They are all SYSTEM user.

By the way that would just close the current instance and open a new one as whatever user and if there is anything passed to the current instance before it is closed that data is lost.

I don't know how to pass data back and forth between instances directly. I tried the tutorials and things I have found in this forum but I can't get that to work mainly I think due to this permissions issue.

Link to comment
Share on other sites

It is php-cgi.exe via the mail function on my Windows 7 Pro 64bit desktop computer. Part of a local testing environment that is not wamp or other similar systems. Installed Apache, php and mysql manually.

I have tried all the solutions I have found here to make CDO SMTP work, the 3rd party msmtp and the older sendmail application for windows. None of them work when run via the testing server php installation. When run directly and even via command prompt manually they work but not when php sends to the programs.

I fell back to testing with AutoIT to see what the issue was but am unable to figure it out. The programs run. They just are not visible except in the taskmanager.

I ended up creating two programs to get email working from my testing server. The first program brings in ConsoleRead data and outputs to a txt file.

The second program which has to run constantly while the server is running checks for this file, if it exists grabs it and parses the data then sends the email. Once the email is sent the file is deleted.

I gave up trying to figure this out and created my work around as explained above. It is not what I would want to have done but I am unable to get any other solution to work. It's a hack around but it does indeed work. This is only for a testing server so something like this is acceptable and I have it on autopilot.

I was hoping to find a proper solution but at least I have a working email solution.

The problem I was trying to get to was that the programs started by php-cgi.exe are run as system user. If I could change the user to my main user account I think it may work but I am not able to do that either and I don't know why.

I am not reinstalling anything so what I put together is my only option to this point and it works BUT I would like to have a fix for this issue which I can't seem to find here.

Thanks for your responses.

Link to comment
Share on other sites

What data is lost? Anything passed on the command line will be kept. There is a flag for RunAs that allows you to keep the parents environment rather than the users as well.

I did not see anything like that in the help documentation for RunAs. Can you direct me to where this is?

My understanding is that once the program that is called or sent data to is closed then that data is gone. Sending data via the command line is kept where? Some cache somewhere in windows? I do not understand how this works.

I as unable to figure out how to send data from one program to another, I read through the manual but the examples given either did not work or where for examples that did not fit what I was trying to do and I did not know how to make them so they would work. I don't see any easy way to do this even though I read through the forum here and some say this is very easy to do but I have not been able to get it to work.

Edited by iAmNewbe
Link to comment
Share on other sites

I am trying to use AutoIT to come up with a solution for this, I was not saying AutoIT was the problem. I did create a working solution with AutoIT even though it is a hack way to do it, the thing works and I can send email from my php test environment now.

The funny thing is, windows XP does not have these problems, only when switching to Windows 7 did I come up against this.

Link to comment
Share on other sites

Sort of went off track here on the topic of this thread but What I was trying to do was change the user running the current program but the solutions provided above did not work on my system with this particular problem. php.cgi.exe is doing something to these applications when it runs them. I even recompiled using CLI in hopes maybe that would do something but no, I had same issue there whether the programs where compiled with CLI or not.

I mean recompiled the AutoIT programs trying both CLI and non CLI to see if it made a difference. It didn't.

Edited by iAmNewbe
Link to comment
Share on other sites

So I guess you would need 2 programs then. Your actual and original program. And one that can start your program as a given user in a given session. Your problem is likely that your process is started in session 0.

Hello, thanks for posting.

What does it mean that the process is started as session 0?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...