trids 2 Posted December 23, 2003 Share Posted December 23, 2003 I'm writing a script that connects to a series of machines on a network, and harvests a logfile from each one's C$ share. But how should I establish the connection to each machine via the C$ share? Rather than force the user to login as the Domain Administrator, I would prefer to iteratively connect to each machine with the login/password from within the script, copy the file, and then move on the next machine. Is this possible in AI3? (On a purely NT4 network)TIA Link to post Share on other sites
scriptkitty 1 Posted December 23, 2003 Share Posted December 23, 2003 (edited) Depending on how you want to do it, there are a few apraoches. One I am leaving out is the reboot one, where you set up to log in on reboot as someone else. You may be able to run a program as a different user on your machine, this would be the command help. RunAsSet ( ["user", "domain", "password"]) Parameters username The user name to use. domain The domain name to use. password The password to use.RunAsSet("Administrator", @Computername, "adminpassword") I use this sometimes in my scripts to enable more privilage than they have. You can run explorer for instance, and access drives that they cannot see, or programs and such. I also make sure to close them at the end of the script. depending on how each computer is set up, this may be a solution for you. The second aproach uses the command line or so. simply link up a drive temporarly. I will doublecheck this later, but here goes. Run(@comspec & " /c net use t: \\computername\sharename[\volume] [password /user:[domainname\]username]", "", @SW_Minimize) Run(@comspec & " /c net use t: \\server\$c Iamgod /user:mydomain\administrator", "", @SW_Minimize) Make sure you have a space before /c might not need the : after the drive letter. Early in the mornin for me again... Also make sure you kill the share right after. you can make persistent drives as well, but for this case you wouldn't want to. Anyway, I thought of showing a few approaches, I use approach #2 for a few things, it isn't very secure, but... Oh yea, you can check drive status and such as well easy with: $var = DriveStatus( "t:\" ) Personally I would set up some other share on the server, and move the files i needed there, and have the server move the one file, update using this, or something. Depends on how secure you want it to be. Edit: Oops, I guess I should read your text closer. The above should work, there is also a little commandline toy that would do nicely for this to copy files from other machines if you have access, as well as actually run programs on thier machine and such, I will post up a link later when I get to work. AutoIt alone would work though. I'm writing a script that connects to a series of machines on a network, and harvests a logfile from each one's C$ share. But how should I establish the connection to each machine via the C$ share? Edited December 23, 2003 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to post Share on other sites
Developers Jos 2,849 Posted December 23, 2003 Developers Share Posted December 23, 2003 (edited) Trids, not sure if this is what you'r looking for, but thought I share it with you... I assume you do this on IP address or PC hostname... you could use the below batchfile to copy from a script or other batchfile. You need to update "K:" to a free drive and the target path\targetfile syntax: copyfile.bat ipaddr user psw file Jos =====start copyfile.bat===== @echo off rem copyfile.bat ipaddr user psw file net use k: /DELETE >NUL 2>nul echo *** create map to %1 net use k: \\%1\c$ %3 /USER:%2 echo Map rc: %ERRORLEVEL% If ERRORLEVEL == 0 goto cpy goto prb :cpy echo *** copy file %4 from %1 copy k:%4 targetpath\%1*.* net use k: /DELETE echo *** Done goto fin :prb Echo *** Problem with the mapping to %1 Pause :fin =====end ============= Edited December 23, 2003 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to post Share on other sites
scriptkitty 1 Posted December 23, 2003 Share Posted December 23, 2003 (edited) One more Idea, depending on access. Anyway just an Idea to toss around in your head. This just uses the standard copy command. $user = InputBox("Question", "Username?", "", "", -1, -1, 0, 0) $password = InputBox("Security Check", "Enter your password.", $password, "*") dim $machine[1000] ;note add all the computer names $machine = "Fred,James,John,April" $machine = StringSplit($machine,",") ;note $machine[0]= the total amount of machines in the array if $machine[0]>0 then for $x= 1 to $machine[0] RunAsSet($user, @Computername, $password) RunWait(@comspec & " /c copy \\$machine[$x]\$c\file.log") next endif Edited December 23, 2003 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to post Share on other sites
trids 2 Posted December 24, 2003 Author Share Posted December 24, 2003 Wow! Thanks for all the ideas folks. I had a peek at the RunAsSet() function, got jealous cos it was marked for "2000 and XP only" .. and failed to see the comment directing NT4 users to the Resource Kit's SU command. Thanks, ScriptKitty, for drawing my attention back in that direction too. I'll explore the suggestions and give feedback here about which way worked out for me. Thanks again folks. Link to post Share on other sites
trids 2 Posted December 30, 2003 Author Share Posted December 30, 2003 Here we go .. feedback as promised. This is the main loop that connects to each machine listed in $asPC[*], and harvests its $sFileRemote into $sHarvestLog ;Connect to each machine in the "PCs" file, and harvest its logfile ProgressOn(@ScriptName,"Remote machines", "") $nPct = 100 / $asPC[0] ;increments for ProgressSet() $nPctDone = 0 For $nX = 1 to $asPC[0] $sSeq = "(" & $nX & " of " & $asPC[0] & ")" ;Announce the PC in the harvest file RunWait(@COMSPEC & " /c echo.>> " & $sHarvestLog, "", @SW_HIDE) RunWait(@COMSPEC & " /c echo --------------------------------------------------------------------------### >> " & $sHarvestLog, "", @SW_HIDE) RunWait(@COMSPEC & " /c echo " & $sSeq & " Harvesting from " & $asPC[$nX] & " >> " & $sHarvestLog, "", @SW_HIDE) RunWait(@COMSPEC & " /c echo.>> " & $sHarvestLog, "", @SW_HIDE) ;Connect a temporary drive to the $sPC's C$ share RunWait(@COMSPEC & " /c net use t: /DELETE", "", @SW_HIDE) RunWait(@COMSPEC & " /c net use t: \\" & $asPC[$nX] & "\" & $sTargetShare & " " & $sAdminPWD & " /USER:" & $sAdminUID, "", @SW_HIDE) ;Harvest the logfile if FileExists($sFileRemote) then ;append the remote file to the $sHarvestLog file.. RunWait(@COMSPEC & " /c copy """ & $sHarvestLog & """ + """ & $sFileRemote & """ """ & $sHarvestLog & """", "", @SW_HIDE) Else ;report failure RunWait(@COMSPEC & " /c echo FAILED. DriveStatus(""T:\"")=" & DriveStatus("T:\") & " >> " & $sHarvestLog, "", @SW_HIDE) Endif $nPctDone = $nPctDone + $nPct ProgressSet( $nPctDone, $sSeq & ": " & $asPC[$nX]) Next Thanks again for the ideas Link to post Share on other sites
scriptkitty 1 Posted December 30, 2003 Share Posted December 30, 2003 Glad it helped. I use those Progress Bars a lot in my finished macros. Nice touch. AutoIt3, the MACGYVER Pocket Knife for computers. Link to post Share on other sites
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