excel macro to execute windows run command?

Badassack

New Member
Joined
Feb 26, 2014
Messages
36
I found the following code here on these forums but it errors out .
I guess X is a variable that needs to be defined? Or is there another method to get the run command to come up?


Sub Macro1()x = Shell("cmd.exe /c C:\TestFolder\Book1.pdf", 1)End Sub</pre>
 
That message means that the end quote for that part of the filename didn't work correctly so it thought that the space was the start of the next argument. Lets try breaking down the string assembly. The following looked like it assembled the correct string to me.

Code:
Sub test()
Dim Str_Reqd As String, x As Long
Str_Reqd = "cmd.exe /c "
Str_Reqd = Str_Reqd & """D:\ssd programs\games\Steam\SteamApps\common\Starbound\win32\asset_unpacker.exe"" "
Str_Reqd = Str_Reqd & """D:\ssd programs\games\Steam\SteamApps\common\Starbound\assets\packed.pak"" "
Str_Reqd = Str_Reqd & "C:\starbound"
'Range("A1") = Str_Reqd ' use this to test the string is assembling properly
x = Shell(Str_Reqd, 1)
End Sub
 
Last edited:
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
That message means that the end quote for that part of the filename didn't work correctly so it thought that the space was the start of the next argument. Lets try breaking down the string assembly. The following looked like it assembled the correct string to me.

Code:
Sub test()
Dim Str_Reqd As String, x As Long
Str_Reqd = "cmd.exe /c "
Str_Reqd = Str_Reqd & """D:\ssd programs\games\Steam\SteamApps\common\Starbound\win32\asset_unpacker.exe"" "
Str_Reqd = Str_Reqd & """D:\ssd programs\games\Steam\SteamApps\common\Starbound\assets\packed.pak"" "
Str_Reqd = Str_Reqd & "C:\starbound"
'Range("A1") = Str_Reqd ' use this to test the string is assembling properly
x = Shell(Str_Reqd, 1)
End Sub

It looked good on the worksheet. But there was no quotes around C:\starbound so i fixed that with """C:\starbound""". It still threw the same error though. Now I also tried this...Str_Reqd = "cmd.exe /k start" just for kicks. And got basically "packed .pak is not a valid win32 application. Which tells me that we got through the first line fine, but failed on the second line because it was treating it as its own separate command and not as a target for the first line. So how do we designate the second line as a target and not a command? If I'm using the right lingo.
 
Upvote 0
CMD.exe may be after a single string, in which case we can try enclosing the entire second command string in quotes. Also I found the return type of Shell is Double (msdn help is good for something :))

Code:
Sub test()
Dim Str_Reqd As String, x As Double
Str_Reqd = "cmd.exe /K """

Str_Reqd = Str_Reqd & """D:\ssd programs\games\Steam\SteamApps\common\Starbound\win32\asset_unpacker.exe"" "
Str_Reqd = Str_Reqd & """D:\ssd programs\games\Steam\SteamApps\common\Starbound\assets\packed.pak"" "
Str_Reqd = Str_Reqd & "C:\starbound"""
'Range("A1") = Str_Reqd ' use this to test the string is assembling properly
x = Shell(Str_Reqd, 1)
End Sub
 
Upvote 0
I've done further testing and think the following may work better.


Code:
Sub test()
Dim Str_Reqd As String, x As Double
Str_Reqd = "cmd.exe /K "

Str_Reqd = Str_Reqd & """""D:\ssd programs\games\Steam\SteamApps\common\Starbound\win32\asset_unpacker.exe"" "
Str_Reqd = Str_Reqd & """D:\ssd programs\games\Steam\SteamApps\common\Starbound\assets\packed.pak"" "
Str_Reqd = Str_Reqd & "C:\starbound"""""
'Range("A1") = Str_Reqd ' use this to test the string is assembling properly
x = Shell(Str_Reqd, 1)
End Sub

Also looking at a batch file unpacker for starbound you may have missed a section of the filepath of the packed file. Should it be?

D:\ssd programs\games\Steam\SteamApps\common\Starbound\win32\assets\packed.pak
 
Upvote 0
I've done further testing and think the following may work better.


Code:
Sub test()
Dim Str_Reqd As String, x As Double
Str_Reqd = "cmd.exe /K "

Str_Reqd = Str_Reqd & """""D:\ssd programs\games\Steam\SteamApps\common\Starbound\win32\asset_unpacker.exe"" "
Str_Reqd = Str_Reqd & """D:\ssd programs\games\Steam\SteamApps\common\Starbound\assets\packed.pak"" "
Str_Reqd = Str_Reqd & "C:\starbound"""""
'Range("A1") = Str_Reqd ' use this to test the string is assembling properly
x = Shell(Str_Reqd, 1)
End Sub

Also looking at a batch file unpacker for starbound you may have missed a section of the filepath of the packed file. Should it be?

D:\ssd programs\games\Steam\SteamApps\common\Starbound\win32\assets\packed.pak

The file paths are correct, were good there. So I ran the program and it came back with "asset_unpacker.exe isn't a valid win32 application." So i went to the program and tried it with "run as administrator" on and off. same thing both ways. But I know it works, so theres some small thing were missing probably, huh? Aren't computers fun?
 
Upvote 0
What version of Windows are you running?
 
Upvote 0
It sounds like a UAC issue. Setting "Run As administrator" changes user access but not the security of the application.

I have not run into this issue myself. A bit of reading suggests that if you were writing a stand alone application then you would include a "manifest file" to handle UAC settings. Since the launcher in this case is excel perhaps there is something in the security settings to allow it. I can't even check at the moment as I've got XL2003 at home.

AFAIK to avoid UAC issues the program could be installed outside of "Program Files" or you could be logged into (not Runas) an Administrator Account.

Sorry I can't be of more help.
 
Upvote 0
Oh man, I figured it out. Your going to shoot me right in the face. So no matter how I tried to run the program it wouldn't work. I even learned how to make a .bat file . It always came back as "not a valid win32 application". So I went to the application and just stared at it for awhile. Then I realized that it said the size was 0kb. I thought how could that be? So i deleted it and revalidated the game files, it re-downloaded the unpacker and viola!! the size is 1378kb. So needless to say I'm an idiot for not thinking of that earlier. Sooo you did help me quite abit and I thank you very much sir. good-day mate.
 
Upvote 0
I'm glad you got it sorted out in the end. I asssumed from other things you'd said that the unpack command was running from the command prompt so I didn't consider file corruption.

I've ended up learning a lot more about UAC (other than i hate it!) so it wasn't a total waste :).
 
Upvote 0

Forum statistics

Threads
1,216,111
Messages
6,128,898
Members
449,477
Latest member
panjongshing

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top