kor Posted April 20, 2011 Posted April 20, 2011 user logging in = user1 Script 1 is compiled (to hide admin username and password for user2) Script 1 uses RunAsWait to run Script 2 as user2 (because user 2 has admin where user1 doesn't) Script 2 has code that relies on @UserName My problem is, I want @Username to be for user1, and not user2. Yes I understand it is working by design because script2 is being run as user2 so obviously the @Username would be user2. I'm asking, is there any workaround to get the ACTUAL user logging in? (user1) ? Is there some way I can pass the @Username from script1 (which is still user1) over to script2 as a variable?
BrewManNH Posted April 20, 2011 Posted April 20, 2011 You could possibly write the @UserName value to an .ini file and then read that back in when the script gets to the RunAs line. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
kor Posted April 20, 2011 Author Posted April 20, 2011 You could possibly write the @UserName value to an .ini file and then read that back in when the script gets to the RunAs line. Yeah, I cheated. I used the clipboard instead since I didn't want to mess with writing and reading files. I wanted something super fast. Used this. In script 1 ClipPut(@UserName) *run script 2* ClipPut("") ; clear clipboard In script 2 $sUserName = ClipGet() $sProgramsDir = "C:\Documents and Settings\" & $sUserName & "\Start Menu\Programs"
MvGulik Posted April 20, 2011 Posted April 20, 2011 Better to spent a little additional time on it and pass that initial @UserName as parameter to the script with run().... or I'm I missing something ... "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...
kor Posted April 20, 2011 Author Posted April 20, 2011 Better to spent a little additional time on it and pass that initial @UserName as parameter to the script with run(). ... or I'm I missing something ... RunAsWait($sAdminUser, $sDomain, $sAdminPass, 0, @AutoItExe & " /AutoIt3ExecuteScript " & $sSysVolDir & "\StudentLogin.au3", @ProgramFilesDir & "\AutoIt3", @SW_HIDE) Let me know what I would need to change in the command to pass that argument and I will.
sahsanu Posted April 20, 2011 Posted April 20, 2011 Let me know what I would need to change in the command to pass that argument and I will. Just put @UserName after StudentLogin.au3 RunAsWait($sAdminUser, $sDomain, $sAdminPass, 0, @AutoItExe & " /AutoIt3ExecuteScript " & $sSysVolDir & "\StudentLogin.au3 " & @UserName, @ProgramFilesDir & "\AutoIt3", @SW_HIDE) Now in your second script (StudentLogin.au3) you should use that parameter: $user = $cmdline[1] MsgBox(0,"","User passed by script1 is " & $user & " and real user is " & @UserName)
smartee Posted April 20, 2011 Posted April 20, 2011 hi kor, You might be interested in passing command line parameters to your script. Search the help-file for "Command Line Parameters". Excerpt from help-file: So if your script is run like this:AutoIt3.exe myscript.au3 param1 "this is another param"$CmdLine[0] equals... 2 $CmdLine[1] equals... param1 $CmdLine[2] equals... this is another param @ScriptName equals... myscript.au3 In addition to $CmdLine there is a variable called $CmdLineRaw that contains the entire command line unsplit, so for the above example: $CmdLineRaw equals... myscript.au3 param1 "this is another param" Hope this helps. -smartee
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