How to script to change Users on Windows...

General Macro Scheduler discussion

Moderators: Dorian (MJT support), JRL

Post Reply
tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

How to script to change Users on Windows...

Post by tommytx » Sun Oct 17, 2010 12:04 am

I know for sure this is a fantastic scripting program... can anyone tell me if there is any possibility it can do this.. .I don't have time or knowledge to do this so I would be willing to buy the script and pay a reasonable fee for somene to do if for me if its possible to begin with... here is the problem:

I have an autoit script running on a windows user site (let's say user John), and after it does a few things on John's user site, I want it to do following:
1. Click "Start Button" (no problem)
2. Click "Log Off" (no problem)
3. Click "Switch User" (no problem)
But that is it... the script of course loses control and cannot click to select the next user...
So of course it can't click what the next user is supposed to do...

Any ideas, thoughts... I was running the initial script from the Administrator User and I also made all the users administrators just so they could order the next user to do something... but once I change user.. I have no idea how to pick it up.... any thoughts or ideas..

The users I am referring to is the normal users that can be assigned to one computer and they can all be logged in and switch from one to the other quickly by logging off one user and logging on another.
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Sun Oct 17, 2010 12:15 am

Just to clarify.. I am not suggesting this has to run by autoit.. I just need any script capable of switching users and then activating a program on that uses site... or even on the administrator site.... I would even consider putting a control program on a plugin in stick.. or what ever you call that little thingy that you plug in that has memory... I just want to gitter dun no matter how I do it..
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Sun Oct 17, 2010 12:25 am

RUNAS USAGE:

RUNAS [ [/noprofile | /profile] [/env] [/netonly] ]
/user: program

RUNAS [ [/noprofile | /profile] [/env] [/netonly] ]
/smartcard [/user:] program

/noprofile specifies that the user's profile should not be loaded.
This causes the application to load more quickly, but
can cause some applications to malfunction.
/profile specifies that the user's profile should be loaded.
This is the default.
/env to use current environment instead of user's.
/netonly use if the credentials specified are for remote
access only.
/savecred to use credentials previously saved by the user.
This option is not available on Windows XP Home Edition
and will be ignored.
/smartcard use if the credentials are to be supplied from a
smartcard.
/user should be in form USER@DOMAIN or DOMAIN\USER
program command line for EXE. See below for examples

Examples:
> runas /noprofile /user:mymachine\administrator cmd
> runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"
> runas /env /user:[email protected] "notepad \"my file.txt\""

NOTE: Enter user's password only when prompted.
NOTE: USER@DOMAIN is not compatible with /netonly.
NOTE: /profile is not compatible with /netonly.
Couldn't you just use "runas" to run a program using another user's account?

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Sun Oct 17, 2010 1:07 am


Couldn't you just use "runas" to run a program using another user's account?

Not sure... let me lay out the whole idea.. so you can fully understand what I am trying to do...

1. I am logged in as administrator so I can go from one user to another without any password at all... or at least that is what is happening...I can go "Start", "Log off", " Switch User" and choose any user and do what ever I want in the account... with no password being requested at all.. that is when I do it manually...

2. So what I want to do is the first thing in the day.. go into each of say 5 users manually and load firefox and go to a specific website and let it cookie the browser... and I want to go to the same site 5 times and let each of 5 copies of fire fox get cookied up.. since each cookie will be different then I can be logged into 5 different accounts at the same time..

3. Once all 5 sites are cookied up and 5 accounts open and ready to go... I suppose I could also figure out how to make the program prepare all 5 and set the cookies and open the accounts, but have been doing that one thing initially manually first thing in the morning... That is a neat idea as it is aggravating to have to visit 5 users and do the same thing 5 times. Oh well...

4. For rest of the day I want to automatically visit each user one after the other at approximately 5 min apart and gather some information from each one of the different open accounts..... then while leaving the account open.. go to the next one and do the same... and keep going from one account to the other all day wihtout closing any.... course I understand that occasionally I might get knocked out of an account so will need to check each time I return to make sure its still open and act on that if for some reason it accidently closed.

5. The reason I was using different users to do this of course is that if you try to use different tabs on firefox (which would be great) it ends up using the same cookie so you would end up in the same account for each tab... by switching to a new user firefox stores the cookie in a different place and does not mix them up..so I can have 5 different accounts open at the same time.... at least that is how I see it..

6. Now that I see the code you wrote above... I am starting to think maybe I should be programming with something...like in a batch file under administrator control.. to switch users and do the work.... I had not thought of that... currently the script I am using is autoit.. and it works great.. as I am filling forms and etc ... but it won't cross over between users... and keep going... at least not for me...

7. So it sounds like I need to study how an adminsistrator writes a program to run around and do stuff in many differeent user accounts... if you fully understand what I am trying to accomplish... and are interested I would love to have a quote on what you could do this for.... of course I would write up the finite details so you could study the exact process before offering a quote... otherwise... I am pretty good at programming and have done some basic stuff with MJnet script and I love it... but this one is autoit.. but I have no problem redoing if it appers mjt stuff will do the best job....

8. anyway has this made it any clearer or more confusing... I thought about trying to use vmware (the virtual stuff)... like 5 operating systems running... but seems a little much and I do not yet know enought about vmware to set up something like that.... besides only one user will be doing any work at a time... they are not all running at same time.. only one after the other so speed is not important.

9. Hope I haven't bit off more than I can chew here...

10. Thanks again for any suggestions..
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Sun Oct 17, 2010 2:00 pm

I created another user on my computer as "user1". Do a "switch user" in the GUI first to properly "setup and initialize" everything. Then "switch user" back to your original logged in user.

I'm already logged on to my yahoo mail account as my regular user.

Then I do this:

C:\Documents and Settings\Computer User>runas /user:user1 "C:\Program Files\Mozilla Firefox\firefox.exe"
Enter the password for user1: (since no password was setup - pressing Enter was sufficient here)
Attempting to start C:\Program Files\Mozilla Firefox\firefox.exe as user 'DELL\user1" ...

This opens firefox in a new window, running AS the new user "user1". I'm able to login to my yahoo mail account a second time, and not "kick out" the first login, because yahoo sees these as "separate" browser sessions. Cookies remain separate and independent as far as I can tell using this method.

I believe with this method you could have 5 instances of firefox running as 5 separate users all at once, and simply navigate between the open applications.

No more "switch user" would be neccessary.

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Sun Oct 17, 2010 2:42 pm

Great... I will try that... you guys are soooooo... smart....
I picked up a copy of Windows Admin Scripting Little Black Book by Jesse Tores via Coriolios... to see if I could learn some basic Administrator Scripting but it seems mostly for setting up remotes and all that sort of stuff.. It does not seem to cover anything about firing off users and doing things in their accounts... without their presence..

IF anyone has come across any examples of scripting users making them act just like they were there it would be greatly appreciated...

I am off to play with the idea you suggested.. thanks adroege... will let you know if it works for me..
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Sun Oct 17, 2010 5:08 pm

C:\Documents and Settings\Computer User>runas /user:user1 "C:\Program Files\Mozilla Firefox\firefox.exe"

This seems like the perfect solution, but I have not gotten my stuff right yet to make it work..

Should all of the url above be placed into the "Start" "Run" cmd box that comes up?

I did check to make sure that my runas command is allowed to run and it is ok for that..

But no matter what command i give the run as nothing happens... using enter for the password in each case since I did not set a password... it does come up and ask for password...

Can you give me a simple format to lets say run notepad from my current user at another user like... for example I am user HP_Administrator at this point...
If I use the following command to run user vabe and its notepad.. will this work..
at the cmd prompt from clicking "Start" and "Run" I type in the cmd box:

Runas /env /user:[email protected] "NOTEPAD \"my file.txt\""
Above is from an example I found now I will convert to what I think applies to me...
Runas /env /user:vabe "NOTEPAD\myfile.txt"
Should this work... does he have too much quote marks up there... looks like a typo... should mine work or do I need the extra quote shown above"

I feel if I can figure out how to run anything that belongs to another user I will be on a roll... Thanks..
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Sun Oct 17, 2010 7:26 pm

runas /user:user1 "C:\Program Files\Mozilla Firefox\firefox.exe"
You have to verify where your installation of firefox lives. The path I gave is correct for my computer, yours may be installed in a different place.
Runas /env /user:[email protected] "NOTEPAD \"my file.txt\""
Just try the simplest example first.... ie. just launch notepad without loading a file. Try like this:

Runas /env /user:[email protected] notepad

Also, as a side note. I think it's best while you are testing to open a CMD window and leave it open. Type your commands at the prompt instead of using Start -> Run. Error messages and the like are more easily spotted that way.

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Sun Oct 17, 2010 8:18 pm

c:\Documents and Settings\HP_Administrator>runas /profile /user:lars "c:\Program Files\Mozilla Firefox\firefox.exe"

Opens up new window with firefox loaded... I navigated to select site.. got cookied and it reqd email and pass to open account.. it placed my email in upper right hand corner with logged in statment..

I view some data in the account and all is well... Then I minimized the foxfire browser and could see that it still said... Lars logged in on minimized line at bottom..


Next I type the below into the still open cmd window.. only difference is now using user "vabe" I also included /profile in hope that if it required the user profile.. maybe it would keep cookies separated....

c:\Documents and Settings\HP_Administrator>runas /profile /user:vabe "c:\Program Files\Mozilla Firefox\firefox.exe"

It opens a new window and loads firefox just like before:
I navigate the new firefox window to the same site and use a new email user name and password and it opens my second account just fine.
I look around the account and all is well with the second account...

I minimze the 2nd window with user "vabe" and maximize the first "lars" user window..

Just as soon as I accessed any information in the first account the user email name changes to the same email password as the second window..
And now I am in the the same account... apparently when you access two copies of firefox from the HP_administrator user.. even though you use runas "lars and runas "vabe" the cookies are still shared as though you are using 2 tabs...

Only when I physically visit each user directly does the cookies stay separate.. and they do keep separate no matter how many times I swictch back and forth.


so bottom line looks like I need to figure out how to switch users via software.. so that the work can be done in the actual account.. vice doing the work from the HP_Administrator account using Runas to get each account.

I am sure something like a batch file run by the administrator can script the change and each time it goes into a user it will activate a small script that will allow me to get info from that account..

Currently I am using an autoit script to gather the data... but I can't figure out how to script the change of user..
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Sun Oct 17, 2010 8:24 pm

I will be more than happy to switch to mjtnet script... if its possible to use it to script a user change and activate a program on arrival.. matter of fact I offer anyone who can make this work $100 bucks.. that is switch from one user to the other and fire off a simple script to do some minimal work with firefox... I just need the ability to go around from user1, 2, 3, 4, and 5 light off my already builts script that will make firefox gather some data then move on to the next user... I already have a functional script that works on making firefox do what I need... just can't figure out how to switch users one by one.... and light off a new script..
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

User avatar
JRL
Automation Wizard
Posts: 3505
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Oct 18, 2010 4:25 am

No guarantees... just a thought.

Kill explorer and do a "runas" of explorer for your users. I think I'd do one at a time going back to the original user in between. This sample kills explorer for the initiating user, "Runs as" explorer for a different user, waits a bit in the spot where you would place your firefox code, then kills the "ran as" explorer and restarts explorer as the initiating user.

When I tried this it brought up the "runas" users desktop and also when I opened Firefox from that users desktop, the cookies were changed under that user's application data. So, it seems to work.

I think it would be easiest if your users did not have passwords but it works with passwords as well. I have the password part remarked out in the sample.

Also, make sure to properly path explorer.exe.

Another also. I'm running XP. I have no idea what will happen in Vista or Win 7.

Code: Select all

Let>Rp_wait=0
Run>taskkill /im explorer.exe /f

//Check for explorer to die before proceeding
Label>Check
  ProcessExists>Explorer.exe,CheckRes
  If>CheckRes=True
    Wait>0.5
    Goto>Check
  EndIf

//Run explorer as a different user,  put in your computername\username
Run>cmd /c runas /user:computername\username C:\WINDOWS\explorer.exe

/*
//Only needed if the user has a password
//I'd recommend no passwords for this process.
Wait>2
SetFocus>cmd.exe*
Send>password
Press Enter

//Check for Explorer to be running before proceeding
Label>Check2
  ProcessExists>Explorer.exe,CheckRes
  If>CheckRes=False
    Wait>0.5
    Goto>Check2
  EndIf



//Do stuff with firefox
//The wait is for demo purposes
Wait>10

//



Run>taskkill /im explorer.exe /f

Label>Check3
  ProcessExists>Explorer.exe,CheckRes
  If>CheckRes=True
    Wait>0.5
    Goto>Check3
  EndIf
  Run>C:\WINDOWS\explorer.exe

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Wed Oct 20, 2010 3:51 am

Thanks for the offer to help, I have been out of town for a couple of days....
I will study this tomorrow to see if I can follow what you are saying.. First let me explain that when I enter the user area, I will need to run fire fox with a grease monkey script.. and IE using an autoit script.. IE will command Fire fox which is being controlled by greasemonkey...

Don't know if this makes sense. but I did try the Runas command on Firefox running each of the 5 users from the Admin user... it worked perfect and allowed me to runas /profile /user:vabe "path to firefox"

Each one worked perfect via runas.. but in every case the cookies mingled just the same as they do when you run browsers in separate tabs...

Now if I run 1 firefox and 1 IE of couse I can have two accounts open on the same site since firefox and IE do not mingle cookies.. but any other instance of FF or IE do mingle the cookies... and even when run using runas... the only way I have found to keep cookies separate is to physically go into each user and do it..

So bottom line it would not work to runas IE since the main program that must remember cookies and accounts is the Firefox...
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Oct 20, 2010 12:15 pm

When JRL refers to "Explorer" he doesn't mean IE.

"Explorer" IS the GUI you see when running Windows. To most people Explorer IS WINDOWS, they don't know that most of the code for the operating system is hidden out of sight, with just a "pretty face" slapped on top.

tommytx
Pro Scripter
Posts: 61
Joined: Mon Dec 22, 2003 3:20 am

Post by tommytx » Wed Oct 20, 2010 1:17 pm

Wow! Thanks... you are right I was off in left field... so I will try the idea.. but I may not really understand enough about it to set it up... will give it a try anyway....
You ain't seen no real estate till you seen http://vahud.com virginia beach real estate at its best.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts