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 have a PC dedicated to running some excel spreadsheets in an automated manner. For this to work properly, a user must be logged in to the machine (preferably the console).

Does anyone know of a tool or script one could run to check whether a session exists, and if not, establish one, passing the appropriate username and password?

share|improve this question

2 Answers 2

To check and see if a particular user is logged on to a particular machine I would use PSLoggedOn

share|improve this answer
    
Right, but I need to be able to force a logon for that user if they are found not to be logged on. –  tbone Jan 27 '11 at 13:45

It might be a worthwhile venture to investigate starting the spreadsheet as a scheduled task (ensuring you've logged in at least once with the account to be used to create a profile), but failing the ability to do that, here's the general guideline.

  • We need to create some entries in HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon that will set the machine to autologin. You can either script these, or manually regedit them to set them to what you want, then export the key.

I haven't tested this with Vista/7, the last time I used it was NT and I haven't time to test this for you right now, but here's the general guideline:

Run this CMD as a scheduled task every so often:

quser|find /i "console"|find /i "myuser"
if not "%ERRORLEVEL%"=="0" goto :INITIALIZE

goto :EOF

:INITIALIZE
: set logon credentials
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultUserName" /t REG_SZ /d "myuser" /f
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "DefaultPassword" /t REG_SZ /d "S3cretstuff" /f

reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "AutoAdminLogon" /t REG_DWORD /d 0x1 /f

shutdown /r /f /c "auto processes not found running"


:EOF

You might also look into something called "registered applications" - it's mentioned in the shutdown help, I've never heard of it.

This should get you started.

share|improve this answer
    
Very interesting, will check this out....thanks for putting it in a batch file, nice approach. –  tbone Jan 27 '11 at 13:47

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.