Simpel Posted September 23, 2019 Posted September 23, 2019 Hi, I tried to make a cui that can get a folder.lnk as parameter and changes the directory in executing cmd.exe to this linked folder. With RunWait and given command I didn't get nothing to work. So I decided to make a batch and RunWait the batch. I compile the script and run it with a linktofolder.lnk as parameter in cmd.exe. The batch is outputting "cd pathtothatfolder" to cmd but not executing it. What did I wrong? #AutoIt3Wrapper_Change2CUI=y Local $sSyntax = "Syntax follow:" & @CRLF & @CRLF & "follow <Verknuepfung>" If $cmdlineraw = "" Then ConsoleWrite($sSyntax & @CRLF) Exit EndIf If Not IsArray($CmdLine) Then ConsoleWrite($sSyntax & @CRLF) Exit EndIf Local $sLink = $CmdLine[1] Local $aPath = FileGetShortcut($sLink) If @error Then $sLink &= ".lnk" $aPath = FileGetShortcut($sLink) If @error Then ConsoleWrite("Parameter is not an existing link" & @CRLF) Exit EndIf If Not FileExists($aPath[0]) Then ConsoleWrite("Link is not an existing path" & @CRLF) Exit EndIf Local $sPath = $aPath[0] Local $sBatch = @ScriptDir & "\follow.bat" Local $sBatchQuoted = '"' & $sBatch & '"' FileDelete($sBatch) FileWrite($sBatch, 'cd ' & $sPath) RunWait(@ComSpec & " /c " & $sBatchQuoted, "", @SW_SHOW) FileDelete($sBatch) If that is working it is getting more difficult. Because many of the folders linked to include spaces in the path. But step by step. How can I get the code above working? Regards, Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
Subz Posted September 24, 2019 Posted September 24, 2019 Just use single/double quotes for example: #include <Array.au3> #include <File.au3> Opt("ExpandVarStrings", 1) Local $aPath = FileGetShortcut(@DesktopDir & "\Shortcut.lnk") If @error Then Exit MsgBox(4096, "FileGetShortcut Error", "Error code: " & @error) Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = "" Local $aSplitPath = _PathSplit($aPath[0], $sDrive, $sDir, $sFileName, $sExtension) If @error Then Exit MsgBox(4096, "_PathSplit Error", "Error code: " & @error) RunWait(@Comspec & ' /k $sDrive$&&cd\&&cd "' & $aPath[0] & '"')
Simpel Posted September 24, 2019 Author Posted September 24, 2019 Thanks @Subz. (Congrats to 2222 posts 😉 ) It seems to change the directory but instantly returns to the directory where I called the compiled cui script. Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
BrewManNH Posted September 24, 2019 Posted September 24, 2019 Once it ends what are you expecting to happen? For me, all it does is it opens a command window and then closes. 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
Simpel Posted September 24, 2019 Author Posted September 24, 2019 I do have folders to summarize thing thematically. There is one holding all my git projects. But there are some projects that don't really exists in this git-folder. These projects are having a link inside this folder, so that I don't have to look around a lot. I know, go to %git% and there are all folders or their links. But if I'm at cmd.exe to do my git stuff I can't navigate to this linked folders - cd path-to-folder.lnk is not working. My intention is to compile my script as link.exe as a cui script and navigate then with link path-to-folder.lnk. Simpel SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
BrewManNH Posted September 24, 2019 Posted September 24, 2019 Post your script so we can see what you're attempting, the posted script doesn't do anything other than opens the command console, changes the directory that it's at, then closes. So, that doesn't do anything for whatever it is you're trying to do. If we know what you're trying to accomplish in total, then we can give you more help. 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
seadoggie01 Posted September 24, 2019 Posted September 24, 2019 He's trying to use his .lnk files as you would in the file explorer... so he wants to execute a script that will take him to the location of the requested link, but in the command prompt, not in the file explorer, if I understand correctly All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
BrewManNH Posted September 24, 2019 Posted September 24, 2019 I understand what the first part is, I want to know what he intends to do with it after he's opened the command window and changed to the correct folder. That part is clear as mud. 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
Simpel Posted September 24, 2019 Author Posted September 24, 2019 (edited) I do have the command window already opened. I'm wasn't aware that this command line will open another command. I thought it will execute the given command line in that command executing the compiled script. So how to achieve that? And after changing to the correct folder I want to git a lot. Edited September 24, 2019 by Simpel Edit: What to do after the script SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
BrewManNH Posted September 24, 2019 Posted September 24, 2019 Does it have to be done in a conolse window, or is there a GUI involved in whatever you're doing? You can write to a console window with Consolewrite, if it's a CUI that you're opening. 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
seadoggie01 Posted September 24, 2019 Posted September 24, 2019 (edited) I thought this was interesting... I wrote a function for it (See the MS docs on ShellLinkObject for details) expandcollapse popupFunc GetLinkPath($link) ; Create the shell object Local $shell = ObjCreate("Shell.Application") ; Path is left of the last \ Local $path = StringLeft($link, StringInStr($link, "\", 0, -1)) ; File name is right of last \ Local $linkName = StringRight($link, StringLen($link) - StringInStr($link, "\", 0, -1)) Local $folder = $shell.NameSpace($path) If Not IsObj($folder) Then Debug("Not folder object") Return SetError(1, 0, False) EndIf Local $myFolderItem = $folder.ParseName($linkName) If Not IsObj($myFolderItem) Then Debug("Unable to find link") Return SetError(2, 0, False) EndIf If Not $myFolderItem.IsLink() Then Debug("This isn't a link") Return SetError(3, 0, False) EndIf Local $ShellLinkObj = $myFolderItem.GetLink() If Not IsObj($ShellLinkObj) Then Debug("Not Shell link object") Return SetError(3, 1, False) EndIf Local $target = $ShellLinkObj.Path Return $target EndFunc Func Debug($Msg) ConsoleWrite($Msg & @CRLF) EndFunc Edited September 24, 2019 by seadoggie01 Forgot the shell object All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Simpel Posted September 24, 2019 Author Posted September 24, 2019 Hm, I do all the git stuff in the console window. Then I will change the directory and git another repository. Best it will do all this in one console window so that I have the whole console history to browse through the typed commands. 6 minutes ago, BrewManNH said: You can write to a console window with Consolewrite, if it's a CUI that you're opening. You mean just ConsoleWrite("cd path-to-folder" @CRLF)? Will give it a try. SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
Simpel Posted September 24, 2019 Author Posted September 24, 2019 @seadoggie01 : warning: $shell: possibly used before declaration. Local $folder = $shell.NameSpace($path) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ What is $shell? SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
Simpel Posted September 24, 2019 Author Posted September 24, 2019 21 minutes ago, Simpel said: You mean just ConsoleWrite("cd path-to-folder" @CRLF)? Will give it a try. That will print the whole 'command' to the command window and return to the prompt but not 'execute' this command. So I guess it is not what @BrewManNH meant. SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
seadoggie01 Posted September 24, 2019 Posted September 24, 2019 Sorry about that, I fixed it! It's... uh... here I'm using it as a hidden file explorer, essentially. Basically, it's a scripting object that we can use to do a lot of different things. All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Simpel Posted September 24, 2019 Author Posted September 24, 2019 @seadoggie01: that works and returns the real path. But that wasn't my problem. That i got working with FileGetShortCut(). My problem is how to get the command line "cd foldername" executed in that command window I currently work in. SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
seadoggie01 Posted September 24, 2019 Posted September 24, 2019 (edited) My apologies. I failed to read everything. (I learned about a new function too! Who knew!) This code seems to work #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Au3Check_Parameters= #include <WinAPI.au3> Local $sSyntax = "Syntax follow:" & @CRLF & @CRLF & "follow <Verknuepfung>" If $cmdlineraw = "" Then ConsoleWrite($sSyntax & @CRLF) Exit EndIf If Not IsArray($CmdLine) Then ConsoleWrite($sSyntax & @CRLF) Exit EndIf Local $sLink = @WorkingDir & "\" & $CmdLine[1] Local $aPath = FileGetShortcut($sLink) If @error Then $sLink &= ".lnk" $aPath = FileGetShortcut($sLink) If @error Then ConsoleWrite("Parameter is not an existing link: " & @error & @CRLF) Exit EndIf If Not FileExists($aPath[0]) Then ConsoleWrite("Link is not an existing path" & @CRLF) Exit EndIf Local $sPath = $aPath[0] Local $hWnd = _WinAPI_GetParent(@AutoItPID) SendKeepActive($hWnd) Send("cd " & $sPath & "{ENTER}") Run it like this... I know, it's weird, but it doesn't work without a pipe (for me anyways). Any command seems to work before the pipe as well cd | <FullScriptPath> <Link> Edit: I added @WorkingDir to the script, which allowed me to use the current directory of the command prompt Edited September 24, 2019 by seadoggie01 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Simpel Posted September 24, 2019 Author Posted September 24, 2019 Thanks for your thoughts. But in my case it is not working. It is only typing (like a typewriter effect) cd path-to-folder and is then sending a newline. Then returning to the current prompt. SciTE4AutoIt = 3.7.3.0 AutoIt = 3.3.14.2 AutoItX64 = 0 OS = Win_10 Build = 19044 OSArch = X64 Language = 0407/german H:\...\AutoIt3\SciTE H:\...\AutoIt3 H:\...\AutoIt3\Include (H:\ = Network Drive) Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.
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