Sign in to follow this  
Followers 0
gr1fter

batch script variables to autoit - help

3 posts in this topic

Hello, this is my batch script which i have been using quite successful and would like to convert it to autoit. I can't seem to get the variables to work.

Batch File

set local
set profilePaths=%allusersprofile:All Users=%
set src=c:\test\application data\*.*
for /d %%a in ("%profilePaths%*.") do xcopy "%src%" "%%a\Application Data" /H /E /I /Y

This is my autoit code which is not working :( :

$src = @ScriptDir & "\Application Data\*.*"
EnvSet("Local")
EnvSet("profilePaths","allusersprofile:All Users=")
RUN (@ComSpec & " /c " & 'for /d %%a in ("%profilePaths%*.") do xcopy ' & '"' & $src & '"' & ' "%%a\Application Data" /H /E /I /Y ',"", @SW_HIDE)

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi,

modified a script for deleting all files in temp folder in every user profile folder and mix it with your xcopy:

#include <file.au3>
$src = @ScriptDir & "\Application Data\*.*"
;get variable SystemDrive
$sysdrive = EnvGet ("SystemDrive")
;get default profile folder
; if you have 64 Bit OS see helpfile RegRead to change code....
$profdir = StringReplace (RegRead ("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory"), _
"%SystemDrive%", $sysdrive)
;get folders in Document and Settings and store in array
$arfolders = _FileListToArray ($profdir, "*", 2)
;Loop over array
For $i = 1 To UBound ($arfolders) - 1
    $run = " /c xcopy " & """" & $src & """" & " " & """" & $profdir & "\" & $arfolders [$i] & "\Application Data""" & " /H /E /I /Y" 
    ;checking run string
    consolewrite ($run & @CRLF)
    ;just delete line with consolewrite and uncomment the Run
    ;Run (@ComSpec & $run,"", @SW_HIDE)
Next

If you want to see code for temp folder deletion with excluding some userprofiles, e.g. LocalService, All Users, NetworkService:

http://www.autoitscript.com/forum/index.php?showtopic=110688&st=0&p=777148&fromsearch=1&#entry777148

;-))

Stefan

Edited by 99ojo

Share this post


Link to post
Share on other sites

Hi,

modified a script for deleting all files in temp folder in every user profile folder and mix it with your xcopy:

#include <file.au3>
$src = @ScriptDir & "\Application Data\*.*"
;get variable SystemDrive
$sysdrive = EnvGet ("SystemDrive")
;get default profile folder
; if you have 64 Bit OS see helpfile RegRead to change code....
$profdir = StringReplace (RegRead ("HKLM\Software\Microsoft\Windows NT\CurrentVersion\ProfileList", "ProfilesDirectory"), _
"%SystemDrive%", $sysdrive)
;get folders in Document and Settings and store in array
$arfolders = _FileListToArray ($profdir, "*", 2)
;Loop over array
For $i = 1 To UBound ($arfolders) - 1
    $run = " /c xcopy " & """" & $src & """" & " " & """" & $profdir & "\" & $arfolders [$i] & "\Application Data""" & " /H /E /I /Y" 
    ;checking run string
    consolewrite ($run & @CRLF)
    ;just delete line with consolewrite and uncomment the Run
    ;Run (@ComSpec & $run,"", @SW_HIDE)
Next

If you want to see code for temp folder deletion with excluding some userprofiles, e.g. LocalService, All Users, NetworkService:

http://www.autoitscript.com/forum/index.php?showtopic=110688&st=0&p=777148&fromsearch=1&#entry777148

;-))

Stefan

Thanks for the response! i was just coming back to respond to my own post on what i did to resolve and looks like you beat me to it.

Here is what i came up with after many trials and errors. Thought I'd share as well to anyone who is interested. Thanks alot!

$src = @ScriptDir & "\Application Data\*.*"

EnvSet("profilePaths","C:\Documents and Settings\")
$var = ENVGet ("profilePaths")
RUN (@ComSpec & " /c " & 'for /d %a in ' & ('("' & $var & "*." & '")') & ' do xcopy ' & '"' & $src & '"' & ' "%a\Application Data" /H /E /I /Y ',"", @SW_HIDE)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0