MrChris Posted June 1, 2006 Share Posted June 1, 2006 I have a batch script I wrote to help in ejecting my usb device from my xp machine. And with the below batch code it works just fine. But I would rather use a autoit script as autoit will produce much prettier looking dialogs then a dos batch window. my current batch script it below. what AutoIt code can I use to produce the same results as the below batch script? eject.cmd: @Echo off goto eject :eject removedrive.exe "SanDisk Cruzer Micro USB Device" if errorlevel 0 goto end if errorlevel 1 goto procexp :procexp start %usbdrive%\eject\procexp.exe :end reg delete "HKCU\Environment" /v usbdrive /f echo. echo You may now safley unplug the "SanDisk Cruzer Micro USB Device" echo. pause exit thanks for any help anyone can provide. MrChris Link to comment Share on other sites More sharing options...
MHz Posted June 1, 2006 Share Posted June 1, 2006 Not sure of %usbdrive%, as if the system allocates this env. variable. Not sure of exitcode result, but have taken a chance of output. This may help to get you started. $exitcode = RunWait('removedrive.exe "SanDisk Cruzer Micro USB Device"') If $exitcode = 0 Then end() ElseIf $exitcode = 1 Then procexp() EndIf Exit Func procexp() RunWait(@ComSpec & ' /c start %usbdrive%\eject\procexp.exe', '', @SW_HIDE) EndFunc Func end() If RegDelete('HKCU\Environment', 'usbdrive') = 1 Then MsgBox(0, '', 'You may now safely unplug the "SanDisk Cruzer Micro USB Device"') EndIf EndFunc Link to comment Share on other sites More sharing options...
MrChris Posted June 1, 2006 Author Share Posted June 1, 2006 @MHz This was a great help. Thank you very much. MrChris Link to comment Share on other sites More sharing options...
MrChris Posted June 1, 2006 Author Share Posted June 1, 2006 (edited) After reading through the help on EnvSet it doesnt look like it is possible to set a env var to such as %cd% to set the var of that the current dir is? in a dos batch file I would just run setx.exe abcdefghi %cd% and if the batch file is run from C:\test then the env var abcdefghi is set to C:\. If I put RunWait('setx.exe abcdefghi %cd%', '', @SW_HIDE) in a blank au3 file it set the var as %cd% rather than a valid drive\path. Edited June 1, 2006 by MrChris Link to comment Share on other sites More sharing options...
MHz Posted June 1, 2006 Share Posted June 1, 2006 After reading through the help on EnvSet it doesnt look like it is possible to set a env var to such as %cd% to set the var of that the current dir is? in a dos batch file I would just run setx.exe abcdefghi %cd% and if the batch file is run from C:\test then the env var abcdefghi is set to C:\. If I put RunWait('setx.exe abcdefghi %cd%', '', @SW_HIDE) in a blank au3 file it set the var as %cd% rather than a valid drive\path.Your confusing me with what you need . In DOS, you would use PUSHD to store the current firectory and change current directory. Then use POPD to return to previous current directory. If C:\test is the current directory, then abcdefghi would equal C:\test if I'm not mistaken. Now EnvSet will set a environment variable, much like what you set in a cmd file for tempory use. EnvSet will last for the life of the script. SetX is a commandline tool to permanently set a environment variable. This is different to the above 2 items yet again as is written permanently to registry. I'm going to guess as you mention last of SetX, of wanting a permanent environment variable. This is what I use to do this ; Example of creating %SendTo% for the userprofile _Variable('User', 'SendTo', '%UserProfile%\SendTo') Func _Variable($type, $key, $value) ; adds a permanent environment variable. Local $environment Switch $type Case 'System' $environment = 'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' Case 'User' $environment = 'HKCU\Environment' Case Else Return EndSwitch If Not RegRead($environment, $key) Then If RegWrite($environment, $key, 'Reg_Expand_sz', $value) Then EnvUpdate() EndIf EndFunc 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