Jump to content

Variable in a command line isn't working - (Moved)


Recommended Posts

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!

Link to comment
Share on other sites

 

in the help file, Macro Reference

Quote
@UserName ID of the currently logged on user.
@UserProfileDir Path to current user's Profile folder.

 

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • Moderators

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 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

Link to comment
Share on other sites

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 by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

#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 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

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...