Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am looking for a way with which i can autostart a certain program on logon of a user with user-rights with administrator-rights.

I already tried using task scheduler but it didn't work out because you got to enter a username with format machine\user and our pxe-image-deployment-system automatically patches the machine names so the entered domain\user stopped working.

UPDATE:
the runas.exe command does not seem appropiate for this task, too. If using /user:machinename\Administrator /savcred it is invalid after imaging. What one user suggested was using .\Administrator or localhost\Administrator but both didn't work on my XP SP3 machines.


UPDATE2:
In the program i need to execute this function is getting used:

    [DllImport("user32.dll")]
    public static extern int ExitWindowsEx(int uFlags, int dwReserved);

when using the programs suggested by Alan Kuras this function is failing, which is a no-go for me.

UPDATE3:
Yes! I got it, I think! It seems like you could not use ExitWindowsEx when running under another users context.
I simply switched my application to WTSLogoffSession and now it's working!

share|improve this question
    
Do You allow using external programs to achive this task ? –  Alan Kuras Jun 21 '12 at 7:10
    
If there is no alternative with built-in tools, yes. –  Zulakis Jun 21 '12 at 7:13

6 Answers 6

up vote 1 down vote accepted

If You have problem to achive this task using built-in functions because of Your deployment system there is a solution, which works for many other things like sending someone program which can be run as Administrator without knowing a password.

Basically You need to create program which contains administrator password and can obtain specified rights running as another user. There are several programs which come to my mind:

Those programs can encrypt You script, username and password and automatically run as local administrator in user environment.

Alternatively if You know some programming language You can write it for urself. Just read about impersonate (for example in C#)

Edit 2 : Second thing which come in to my mind. If You have problem obtaining computername You can try to use %COMPUTERNAME% variable like %COMPUTERNAME%\Administrator and check if that works.

share|improve this answer
    
Thanks for your answer. %COMPUTERNAME% did not work after deploying to other machines. Are there any open source programs which can achieve this? A C# tutorial with more detail then the msdn would also be interesting. –  Zulakis Jun 21 '12 at 7:35
    
After reading the documentation of the programs you mentioned, i noticed that CPAU needs a similar syntax domain\user so this will probably fail too. Runasspc has a localhost switch, but might replace this to the hostname internally too. I will have to try this out. –  Zulakis Jun 21 '12 at 7:37
    
Encrypted RunAs have localhost switch too. Maybe source-code.biz/snippets/c/1.htm MiniRunAs will work (Opensource) –  Alan Kuras Jun 21 '12 at 7:45
    
Got it, I think. See my updated initial post. Thanks for you help! –  Zulakis Jun 21 '12 at 11:48
    
No problem, glad i can help! –  Alan Kuras Jun 21 '12 at 11:48

I solved this by using a alternative runas program, CPAU.

share|improve this answer

It's an around the bush method, but when we used to image machines using Clonezilla PXE we had a batch file in the XP "Startup" folder that would get kicked off on first login. The batch file would add 4 or 5 scheduled tasks then delete itself.

You can use "SCHTASKS /Create" to add a task. here's an example if your interested in using this method.

SCHTASKS /Create /RU username /RP password /SC hourly /D * /M * /TN taskname /TR C:\folder\process.bat /ST 12:00 /SD 06/20/2012 /F

SCHTASKS /Create /? will provide you with the help information.

share|improve this answer
    
I would rather not like to use this method because i do not like having passwords in batch files. Also, this would not work for what i want because the Task should be executed on logon, but the autostart is going to executed so the task won't run. –  Zulakis Jun 19 '12 at 14:22

Easy. Like msindle suggested, you'll want to put the shortcut in the startup folder, but if it needs to run as an admin, you'll have to a) provide the admin credentials the first time it runs, and b) use some command line switches. For example, the below is how I run ADUC as a domain admin, while logging on to my machine as a limited user. ("Target" field of the shortcut.)

%windir%\system32\runas.exe  /user:domain\adminuser /savcred "mmc %windir%\system32\dsa.msc"

First bit calls runas.exe, which is what lets you run a program as a different user in XP, /user specifies the user (if you want a local account, user the machine name instead of the domain name), /savcred allows the credentials to be saved (after entering them once), and the last bit is what program's being called - Microsoft Management console with the dsa (ADUC) snap-in.

EDIT:

I've also had success with:

%windir%\system32\runas.exe /user:.\username /savcred "mmc %windir%\system32\dsa.msc"

and:

%windir%\system32\runas.exe /user:localhost\username /savcred "mmc %windir%\system32\dsa.msc"

But, according to the comments below, this might not be normal behavior.

share|improve this answer
    
I am pretty sure that this will not work, because the machinename changes (pxe-imaging-system) and the saved credentials won't be valid anymore. –  Zulakis Jun 19 '12 at 19:38
    
In that case, instead of the machine name, try ".\" (without the quotes). Not sure if it'll work from an XP command line (or come to think of it, if it maybe needs quotes on a command line), but .\ is Windows shorthand for local machine. –  HopelessN00b Jun 19 '12 at 19:52
    
If i use .\ i get a User Account not found Error. –  Zulakis Jun 19 '12 at 20:06
    
Well, then it sounds like the user you're trying to use doesn't exist ont he local machine. Is it a domain account, perhaps? I just checked, and %windir%\system32\runas.exe /user:.\test /savcred "mmc %windir%\system32\dsa.msc" worked for me, and ran the program under the account named "test" I set up on my local machine. –  HopelessN00b Jun 19 '12 at 20:20
    
Well, just changing the . to the local machine name made it work. I am using a Windows-XP SP3 machine. –  Zulakis Jun 19 '12 at 20:24

This works for me:

in the target field of shortcut which runs your program add bold text as below C:\WINDOWS\system32\runas.exe /user:Username /savcred "program_path\program_name.exe"

p.s. check your windows system path too !!!

Username must be that username in which account the program_name.exe have been installed

share|improve this answer

Can you put a shortcut to the program in the All Users startup folder and give domain users rights to that program's install directory? If that isn't an option, try doing this: http://www.sevenforums.com/tutorials/208799-programs-documents-run-user-logon.html

Its for Win 7 but I would imagine XP has the same functionality.

share|improve this answer
    
This doesn't start the program as administrator. –  Zulakis Jun 19 '12 at 19:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.