Chimaera Posted September 5, 2012 Share Posted September 5, 2012 Ok as part of a backup script im doing i needed it to backup the usernames individually with data So i borrowed this from BrewmanNH and adapted it expandcollapse popup#RequireAdmin #include #include Global $Os _OsDetect($Os) Local $Users = _UserList() Func _UserList() ;BrewmanNH origanal author Local $UserList, $aUserList, $X, $aUserList[10], $UserList[10], $sUserList[10] If $Os = "V-" Then $UserList = _FileListToArray("C:\Documents and Settings", "*.*", 2) For $I = 1 To $UserList[0] Select Case $UserList[$I] = "All Users" Case $UserList[$I] = "Default User" Case $UserList[$I] = "NetworkService" Case $UserList[$I] = "LocalService" Case $UserList[$I] = "Administrator" Case Else $aUserList[$X] = $UserList[$I] $X += 1 If $X >= UBound($aUserList) Then ReDim $aUserList[UBound($aUserList) + 10] EndIf EndSelect Next Else $UserList = _FileListToArray("C:\Users", "*.*", 2) For $I = 1 To $UserList[0] Select Case $UserList[$I] = "All Users" Case $UserList[$I] = "Default" Case $UserList[$I] = "Default User" Case $UserList[$I] = "Public" Case Else $aUserList[$X] = $UserList[$I] $X += 1 If $X >= UBound($aUserList) Then ReDim $aUserList[UBound($aUserList) + 10] EndIf EndSelect Next EndIf ReDim $aUserList[$X] _ArrayDisplay($aUserList) $sUserList = _ArrayToString($aUserList, "|") ConsoleWrite($sUserList & @CRLF) Return $sUserList EndFunc ;==>_UserList Func _OsDetect(ByRef $Os) If @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Or @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Then $Os = "V-" Else $Os = "V+" EndIf ;~ ConsoleWrite($Os & @CRLF) Return $Os EndFunc ;==>_OsDetect Now im using this to backup the files which works fine but only backs up the current user $iRB_PID = Run("robocopy.exe" & " " & @DesktopDir & " " & $sDestination & "\Desktop" & " " & $sRoboFilesAll & " " & $sRoboSettings, "", @SW_HIDE) While ProcessExists($iRB_PID) If $fInterrupt Then $fInterrupt = False ProcessClose($iRB_PID) Return EndIf WEnd But im trying to adapt it like this but it doesnt seem to work For $loop = 1 To $aUserList[0] $iRB_PID = Run("robocopy.exe" & " " & '"' & $Users & "\" & @DesktopDir & '"' & " " & '"' & $sDestination & '"' & $Users & "\Desktop" & " " & $sRoboFilesAll & " " & $sRoboSettings, "", @SW_HIDE) While ProcessExists($iRB_PID) If $fInterrupt Then $fInterrupt = False ProcessClose($iRB_PID) Return EndIf WEnd Next I need it to use the first script to get the names then cycle through them performing the backup for each name it finds to the given destination Any thoughts where im going wrong? If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
BrewManNH Posted September 5, 2012 Share Posted September 5, 2012 Where are you putting that last snippet of code? Because if it's outside the userlist function, $aUserlist will be empty and undeclared. You declare it as local inside the Userlist function (you actually declare it twice in there). 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 Link to comment Share on other sites More sharing options...
Chimaera Posted September 5, 2012 Author Share Posted September 5, 2012 Yes its lower down in the backup section outside of the userlist function I thought calling this set the function ready Local $Users = _UserList() then it would make it available for the backup section lower down If Ive just helped you ... miracles do happen. Chimaera CopyRobo() * Hidden Admin Account Enabler * Software Location From Registry * Find Display Resolution * _ChangeServices() Link to comment Share on other sites More sharing options...
BrewManNH Posted September 5, 2012 Share Posted September 5, 2012 That function returns the string $sUserlist so $Users is going to equal that string after it's called. Any variables declared local inside a function cease to exist after the function ends/returns. 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 Link to comment Share on other sites More sharing options...
storme Posted September 6, 2012 Share Posted September 6, 2012 G'day M8 I think this is what you maybe looking for. It isn't totally working but it will print out the robocopy command line for you to check. Let me know how it goes. expandcollapse popup#RequireAdmin #include <Array.au3> #include <File.au3> Global $Os = _OsDetect() Local $aUsers = _UserList() _ArrayDisplay($aUsers) Local $sDestination = "*destination*" Local $sRoboFilesAll = "*$sRoboFilesAll*" Local $sRoboSettings = "*$sRoboSettings*" Local $loop ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aUsers[0] = ' & $aUsers[0] & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console For $loop = 0 To UBound($aUsers)-1 ConsoleWrite("robocopy.exe" & " " & '"C:Documents and Settings' & $aUsers[$loop] & 'desktop" "' & $sDestination & $aUsers[$loop] & 'Desktop"' & " " & $sRoboFilesAll & " " & $sRoboSettings & @cr) #cs $iRB_PID = Run("robocopy.exe" & " " & '"' & $Users & "" & @DesktopDir & '"' & " " & '"' & $sDestination & '"' & $Users & "Desktop" & " " & $sRoboFilesAll & " " & $sRoboSettings, "", @SW_HIDE) While ProcessExists($iRB_PID) If $fInterrupt Then $fInterrupt = False ProcessClose($iRB_PID) Return EndIf WEnd #ce Next Func _UserList() ;BrewmanNH origanal author Local $UserList, $aUserList, $X, $aUserList[10], $UserList[10], $sUserList[10] If $Os = "V-" Then $UserList = _FileListToArray("C:Documents and Settings", "*.*", 2) For $I = 1 To $UserList[0] Select Case $UserList[$I] = "All Users" Case $UserList[$I] = "Default User" Case $UserList[$I] = "NetworkService" Case $UserList[$I] = "LocalService" Case $UserList[$I] = "Administrator" Case Else $aUserList[$X] = $UserList[$I] $X += 1 If $X >= UBound($aUserList) Then ReDim $aUserList[UBound($aUserList) + 10] EndIf EndSelect Next Else $UserList = _FileListToArray("C:Users", "*.*", 2) For $I = 1 To $UserList[0] Select Case $UserList[$I] = "All Users" Case $UserList[$I] = "Default" Case $UserList[$I] = "Default User" Case $UserList[$I] = "Public" Case Else $aUserList[$X] = $UserList[$I] $X += 1 If $X >= UBound($aUserList) Then ReDim $aUserList[UBound($aUserList) + 10] EndIf EndSelect Next EndIf ReDim $aUserList[$X] _ArrayDisplay($aUserList) ;$sUserList = _ArrayToString($aUserList, "|") ;ConsoleWrite($sUserList & @CRLF) Return $aUserList EndFunc ;==>_UserList Func _OsDetect() If @OSVersion = "WIN_2000" Or @OSVersion = "WIN_2003" Or @OSVersion = "WIN_XP" Or @OSVersion = "WIN_XPe" Then Return "V-" Else Return "V+" EndIf ;~ ConsoleWrite($Os & @CRLF) ;Return $Os EndFunc ;==>_OsDetect Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
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