BDeav323 Posted July 19, 2018 Posted July 19, 2018 Hello, I'm a relatively new user and I could use some help. I'm trying to run a command to change to a certain folder and then rename a specific folder. The problem is that one of folder names is user specific (it's their user id). If I hard code the user id the command runs correctly. But if I insert a variable in place of the userid the command does nothing. I've tried various different syntax but to no avail. I know my inputbox is working because I've tested that value entered is correct. Here are the 2 lines: $userid = InputBox("User ID", "Please enter your PSEG User ID") RunWait('cmd /c "c: && cd\users\$userid\appdata\local\microsoft && ren outlook outlookORIG"') This was my original attempt. The script doesn't fail but it also doesn't change the outlook folder name. Since this attempt I have tried various versions of extra quotes and such but have had no luck. I've searched Help and forums but haven't found anything. Any help and/or suggestions would be appreciated. Thanks!
Earthshine Posted July 19, 2018 Posted July 19, 2018 (edited) in the help file, Macro Reference Quote @UserName ID of the currently logged on user. @UserProfileDir Path to current user's Profile folder. Edited July 19, 2018 by Earthshine My resources are limited. You must ask the right questions
Moderators JLogan3o13 Posted July 19, 2018 Moderators Posted July 19, 2018 Moved to the appropriate forum, as the Developer General Discussion forum very clearly states: Quote General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here. Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums. Moderation Team "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
careca Posted July 19, 2018 Posted July 19, 2018 How would the command hardcoded look like? Let's take an example with a variable or macro integrated: This is the string to take "C:\Users\W10\AppData\Local\AMD" This is what it looks like with macro: "C:\Users\"&@UserName&"\AppData\Local\AMD" This is with a variable: $var1 = "C:\Users\W10\" $var2 = "AppData\Local\AMD" $var1&$var2 Maybe show us the batch cmd or whatever it was and lets go from there. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
BDeav323 Posted July 19, 2018 Author Posted July 19, 2018 Hello again, First - I apologize for posting in the wrong area. Second thank you for the responses. To try and be more clear, when I run the following command: RunWait('cmd /c "c: && cd\users\12345\appdata\local\microsoft && ren outlook outlookORIG"') The outlook folder does get renamed to outlookORIG But when I change 12345 to a variable name I haven't been able to get it to work. I tried the macro and syntax "careca" suggested: RunWait('cmd /c "c: && cd\users\"&@UserName&"\appdata\local\microsoft && ren outlook outlookORIG"') but still no luck. Thanks
careca Posted July 19, 2018 Posted July 19, 2018 (edited) What if you set the string prior to the cmd? $cmdvar = 'cmd /c "c: && cd\users\"'&@UserName&'"\appdata\local\microsoft && ren outlook outlookORIG"' Run($cmdvar) Edited July 19, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
BDeav323 Posted July 19, 2018 Author Posted July 19, 2018 Unfortunately it gets the same result. Hard coded works, but macro does not.
Earthshine Posted July 19, 2018 Posted July 19, 2018 (edited) how about you post your code instead of making us guess at what is going on? your's is not the same as careca's his $cmdvar = 'cmd /c "c: && cd\users\"'&@UserName&'"\appdata\local\microsoft && ren outlook outlookORIG"' Run($cmdvar) yours RunWait('cmd /c "c: && cd\users\"&@UserName&"\appdata\local\microsoft && ren outlook outlookORIG"') Edited July 19, 2018 by Earthshine My resources are limited. You must ask the right questions
BDeav323 Posted July 19, 2018 Author Posted July 19, 2018 @Earthshine - I've posted the line I'm having issues with. I don't know what else you would need? The lines I posted are all I'm working with at the moment. If I can't get this to work then anything else I do is useless.
BDeav323 Posted July 19, 2018 Author Posted July 19, 2018 To be clear, I ran this line as cara suggested: $cmdvar = 'cmd /c "c: && cd\users\"'&@UserName&'"\appdata\local\microsoft && ren outlook outlookORIG"'Run($cmdvar) and got the same result. I'm sorry if that wasn't clear. I didn't think I needed to post it.
careca Posted July 19, 2018 Posted July 19, 2018 (edited) There's another option, it is to write to console directly... but it's messy, little bit anyway. Maybe that way you can use the macro.. Example: expandcollapse popup#RequireAdmin #include 'AutoItConstants.au3' Read() ;'cmd /c "c: && cd\users\"'&@UserName&'"\appdata\local\microsoft && ren outlook outlookORIG"' Func Read() $getname = Run('cmd', '', @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD);@SW_HIDE $begin = TimerInit() Do $dif = TimerDiff($begin) $Read = StdoutRead($getname, True, False) $Str = StringInStr($Read, 'Microsoft', 1) Sleep(100) If $dif >= 3000 Then ExitLoop Until $Str <> 0 ;============================================================================= StdinWrite($getname, 'cd\users\"'&@UserName&'"\appdata\local\microsoft' & @CRLF) $begin = TimerInit() Do $dif = TimerDiff($begin) $Read = StdoutRead($getname, True, False) $Str = StringInStr($Read, "\appdata\local\microsoft", 1) Sleep(100) If $dif >= 3000 Then ExitLoop Until $Str <> 0 ;============================================================================= StdinWrite($getname, 'ren outlook outlookORIG' & @CRLF) $begin = TimerInit() Do $dif = TimerDiff($begin) $Read = StdoutRead($getname, True, False) $Str = StringInStr($Read, "outlook", 1) Sleep(100) If $dif >= 3000 Then ExitLoop Until $Str <> 0 ;============================================================================= MsgBox(64, '$Read', $Read) EndFunc Updated code, works for me. Edited July 19, 2018 by careca Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
BDeav323 Posted July 19, 2018 Author Posted July 19, 2018 I rebooted my machine and now: RunWait('cmd /c "c: && cd\users\"'&@UserName&'"\appdata\local\microsoft && ren outlook outlookORIG"') and $cmdvar = 'cmd /c "c: && cd\users\"'&@UserName&'"\appdata\local\microsoft && ren outlook outlookORIG"' ;Run($cmdvar both work! Not really sure what freed up when I rebooted or if it will happen again but at least now I know it works. Thanks careca for all the help!
careca Posted July 19, 2018 Posted July 19, 2018 np, glad it's now working. Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe
Subz Posted July 19, 2018 Posted July 19, 2018 Wouldn't it be easier to just use something like: nb: Remove MsgBox function if you want to rename the folder Local $sOutlookPath = @LocalAppDataDir & "\Microsoft\Outlook\" If FileExists($sOutlookPath) Then MsgBox(4096, "Outlook Folder Exists", "Outlook Folder: " & $sOutlookPath) ;~ FileMove($sOutlookPath, $sOutlookPath & "ORIG") careca 1
BDeav323 Posted July 20, 2018 Author Posted July 20, 2018 13 hours ago, Subz said: Wouldn't it be easier to just use something like: nb: Remove MsgBox function if you want to rename the folder Local $sOutlookPath = @LocalAppDataDir & "\Microsoft\Outlook\" If FileExists($sOutlookPath) Then MsgBox(4096, "Outlook Folder Exists", "Outlook Folder: " & $sOutlookPath) ;~ FileMove($sOutlookPath, $sOutlookPath & "ORIG") Thanks for the suggestion Subz! I will look into this as I continue to update and modify this script going forward.
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