iAmNewbe Posted November 15, 2012 Posted November 15, 2012 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.
Mat Posted November 15, 2012 Posted November 15, 2012 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. AutoIt Project Listing
iAmNewbe Posted November 15, 2012 Author Posted November 15, 2012 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.
Mat Posted November 15, 2012 Posted November 15, 2012 (edited) 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. Edited November 15, 2012 by Mat AutoIt Project Listing
jmon Posted November 15, 2012 Posted November 15, 2012 It seems that your problem don't have anything to do with autoit. Maybe you should read some help on the program that is spawning your autoit script. What is the program executing your autoit script? [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center]
joakim Posted November 15, 2012 Posted November 15, 2012 How is the program executed/started? Is it from a windows service as start=auto, or is it running after Logon UI?
iAmNewbe Posted November 15, 2012 Author Posted November 15, 2012 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.
iAmNewbe Posted November 15, 2012 Author Posted November 15, 2012 (edited) 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 November 15, 2012 by iAmNewbe
iAmNewbe Posted November 15, 2012 Author Posted November 15, 2012 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.
iAmNewbe Posted November 15, 2012 Author Posted November 15, 2012 (edited) 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 November 15, 2012 by iAmNewbe
iAmNewbe Posted November 15, 2012 Author Posted November 15, 2012 Running my autoIT programs directly eveything works great. I never came across something like this before and was hoping AutoIT had a solution. Thanks.
joakim Posted November 15, 2012 Posted November 15, 2012 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.
iAmNewbe Posted November 15, 2012 Author Posted November 15, 2012 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now