Jump to content
UBot Underground

Shell command help. I WILL PAY FOR A WORKING SHELL


Recommended Posts

What I am trying to do is use the shell command to unzip a .zip file to a specified folder.

 

It should:

create folder (UI text area command)

unzip specified zip file (UI open file command) to created folder

 

 

Really need this functionality,

let me know your thoughts, ideas, and feedback.

 

TJ

Link to post
Share on other sites

Microsoft does not provide that.

This one uses vbscript.

unzip-vbs.ubot

 

vbscript:

set sa = CreateObject("Shell.Application") 

ReDim strArgumentArray(0)
Dim strFlag,objArgs
Dim strType,strInputType
Dim strComputer
Dim strMessage

Set objArgs = WScript.Arguments
'Get the command line arguments
For i = 0 to objArgs.count - 1
  ReDim Preserve strArgumentArray(i)
  strArgumentArray(i) = objArgs.item(i)
Next

strFlag = strArgumentArray(0)

If strFlag = "" then                    'No arguments have been received
 workmsgout = "Please specific parameters : " & wscript.scriptname & " /unzipfile:directoryandfilename /putfilehere:directory"
 msgout = workmsgout
 wscript.echo msgout
 Wscript.Quit
End If

For i = 0 to UBound(strArgumentArray)

 strFlag = Left(strArgumentArray(i), InStr(1, strArgumentArray(i), ":")-1)

 'Prevent parameter error : An error occurs if there is no : in the string
 If Err.Number Then
   Err.Clear
   msgout = strArgumentArray(i) & " is NOT recognized as a valid input."
   wscript.echo msgout
   Wscript.Quit
 Else
   Select Case LCase(strFlag)
     Case "/unzipfile"
       pathToZipFile = Right(strArgumentArray(i), Len(strArgumentArray(i))-11)
     Case "/putfileshere"
       extractTo = Right(strArgumentArray(i), Len(strArgumentArray(i))-14)
    Case else
       msgout = strArgumentArray(i) & " is not recognized as a valid input."
       wscript.echo msgout
   End Select
 End If
Next


'pathToZipFile="C:\dnld\ubotstudio\samplescript\zipped-file.zip"
'extractTo="C:\dnld\unzip"

set filesInzip=sa.NameSpace(pathToZipFile).items
sa.NameSpace(extractTo).CopyHere(filesInzip)

 

Kevin

Link to post
Share on other sites

Microsoft does not provide that.

This one uses vbscript.

unzip-vbs.ubot

 

vbscript:

set sa = CreateObject("Shell.Application") 

ReDim strArgumentArray(0)
Dim strFlag,objArgs
Dim strType,strInputType
Dim strComputer
Dim strMessage

Set objArgs = WScript.Arguments
'Get the command line arguments
For i = 0 to objArgs.count - 1
  ReDim Preserve strArgumentArray(i)
  strArgumentArray(i) = objArgs.item(i)
Next

strFlag = strArgumentArray(0)

If strFlag = "" then                    'No arguments have been received
 workmsgout = "Please specific parameters : " & wscript.scriptname & " /unzipfile:directoryandfilename /putfilehere:directory"
 msgout = workmsgout
 wscript.echo msgout
 Wscript.Quit
End If

For i = 0 to UBound(strArgumentArray)

 strFlag = Left(strArgumentArray(i), InStr(1, strArgumentArray(i), ":")-1)

 'Prevent parameter error : An error occurs if there is no : in the string
 If Err.Number Then
   Err.Clear
   msgout = strArgumentArray(i) & " is NOT recognized as a valid input."
   wscript.echo msgout
   Wscript.Quit
 Else
   Select Case LCase(strFlag)
     Case "/unzipfile"
       pathToZipFile = Right(strArgumentArray(i), Len(strArgumentArray(i))-11)
     Case "/putfileshere"
       extractTo = Right(strArgumentArray(i), Len(strArgumentArray(i))-14)
    Case else
       msgout = strArgumentArray(i) & " is not recognized as a valid input."
       wscript.echo msgout
   End Select
 End If
Next


'pathToZipFile="C:\dnld\ubotstudio\samplescript\zipped-file.zip"
'extractTo="C:\dnld\unzip"

set filesInzip=sa.NameSpace(pathToZipFile).items
sa.NameSpace(extractTo).CopyHere(filesInzip)

 

Kevin

 

 

Seems like this would work

However on testing came up with an error for line

 

strFlag = Left(strArgumentArray(i), InStr(1, strArgumentArray(i), ":")-1)

 

 

Error reads

Invalid procedure call or argument: 'Left'

code: 800A0005

Link to post
Share on other sites

I will be more than happy to fix this. I will need your help. It works for me here.

 

This will run the Vbscript in a command prompt window.

 

unzip-vbscript /putfileshere:whereever /unzipfile:zipfile

ex.

 

unzip-vbscript /putfileshere:c:\download\unziparea /unzipfile:c:\download\zippedarea\azipfile.zip

 

I figured it out. There seems to me an extra character or two in the arguments missing the ":" being passed to the vbscript. I can check for that but the script will stop because of invalid arguments. Easier to just remove the extra stuff.

 

My sample vbscript bot did not have anything extra.

 

Update to vbs code.

Added checks for valid data being passed.

It will create the output target directory if it does not exist.

Skip the unzip if the zip file is missing.

 

Set fso = CreateObject("Scripting.FileSystemObject")
set sa = CreateObject("Shell.Application")

ReDim strArgumentArray(0)
Dim strFlag,objArgs
Dim strType,strInputType
Dim strComputer
Dim strMessage

Set objArgs = WScript.Arguments
'Get the command line arguments
For i = 0 to objArgs.count - 1
  ReDim Preserve strArgumentArray(i)
  strArgumentArray(i) = objArgs.item(i)
Next

strFlag = strArgumentArray(0)

If strFlag = "" then                    'No arguments have been received
 workmsgout = "Please specific parameters : " & wscript.scriptname & " /unzipfile:directoryandfilename /putfileshere:directory"
 msgout = workmsgout
 wscript.echo msgout
 Wscript.Quit
End If

For i = 0 to UBound(strArgumentArray)

 'wscript.echo strArgumentArray(i) 
 strFlag = Left(strArgumentArray(i), InStr(1, strArgumentArray(i), ":")-1)

 'Prevent parameter error : An error occurs if there is no : in the string
 If Err.Number Then
   Err.Clear
   msgout = strArgumentArray(i) & " is NOT recognized as a valid input."
   wscript.echo msgout
   Wscript.Quit
 Else
   Select Case LCase(strFlag)
     Case "/unzipfile"
       pathToZipFile = Right(strArgumentArray(i), Len(strArgumentArray(i))-11)
     Case "/putfileshere"
       extractTo = Right(strArgumentArray(i), Len(strArgumentArray(i))-14)
    Case else
       msgout = strArgumentArray(i) & " is not recognized as a valid input."
       wscript.echo msgout
   End Select
 End If
Next

'create folder if it does not exist
If NOT fso.FolderExists(ExtractTo) Then
 fso.CreateFolder(ExtractTo)
End If
'do nothing if zip file is missing
if fso.fileexists(pathToZipFile) then
 set filesInzip=sa.NameSpace(pathToZipFile).items
 sa.NameSpace(extractTo).CopyHere(filesInzip)
end if

 

Thanks,

Kevin

Link to post
Share on other sites

I updated the VBScript code to check for the extra characters.

 

Once the character(s) are identified a simple adjustment of bot shell would do the trick.

 

Set fso = CreateObject("Scripting.FileSystemObject")
set sa = CreateObject("Shell.Application")

ReDim strArgumentArray(0)
Dim strFlag,objArgs
Dim strType,strInputType
Dim strComputer
Dim strMessage

Set objArgs = WScript.Arguments
'Get the command line arguments
For i = 0 to objArgs.count - 1
  ReDim Preserve strArgumentArray(i)
  strArgumentArray(i) = objArgs.item(i)
Next

strFlag = strArgumentArray(0)

If strFlag = "" then                    'No arguments have been received
 workmsgout = "Please specific parameters : " & wscript.scriptname & " /unzipfile:directoryandfilename /putfileshere:directory"
 msgout = workmsgout
 wscript.echo msgout
 Wscript.Quit
End If

For i = 0 to UBound(strArgumentArray)

 strFlag = Left(strArgumentArray(i), len(strArgumentArray(i)))
 if instr(1,strFlag,":") then
   strFlag = Left(strArgumentArray(i), InStr(1, strArgumentArray(i), ":")-1)
 end if  
 'Prevent parameter error : An error occurs if there is no : in the string
 If Err.Number Then
   Err.Clear
   msgout = strArgumentArray(i) & " is NOT recognized as a valid input."
   wscript.echo msgout
   Wscript.Quit
 Else
   Select Case LCase(strFlag)
     Case "/unzipfile"
       pathToZipFile = Right(strArgumentArray(i), Len(strArgumentArray(i))-11)
     Case "/putfileshere"
       extractTo = Right(strArgumentArray(i), Len(strArgumentArray(i))-14)
    Case else
       msgout = strArgumentArray(i) & " is not recognized as a valid input."
       wscript.echo msgout
   End Select
 End If
Next

'create folder if it does not exist
if ExtractTo>"" then
 If NOT fso.FolderExists(ExtractTo) Then
   fso.CreateFolder(ExtractTo)
 End If
end if
'do nothing if zip file is missing
if pathToZipFile>"" then
 if fso.fileexists(pathToZipFile) then
   set filesInzip=sa.NameSpace(pathToZipFile).items
   sa.NameSpace(extractTo).CopyHere(filesInzip)
 end if
end if

 

Thanks,

Kevin

I am working on the messenger thing.

Link to post
Share on other sites

Take a look in my sample bot I provided when I posted the vbscript.

 

Using the original example utilizes 7zip (slightly modified)

 

Came back with error

path/to/zip.zip is not recognized as a valid input

 

 

line: 60

Char: 5

Unspecified error

code: 80004005

source null

 

 

I have attached what I have in my .ubot

 

Using 2 UI elements to set

Name of folder to save to

And open the path to the zip file

 

 

It creates the vbs file on the desktop, and the folder to save to, than attempts to execute the shell command to run the vbscript file

 

which at that point brings back the error.

 

 

after the shell runs it removes the vbscript file from the desktop area.

move the stop script node up 1 if you wish to have it not delete the file for testing.

 

I do appreciate your help on this.

 

 

TJ

Link to post
Share on other sites

TJ,

 

That worked fine for me.

 

Kevin

 

I did add more code to replace "/" with "\" in the vbscript. My testing pop a message error message when I sent it unix file names.

 

Attached bot with replace updates.

unzip to folder.ubot

Link to post
Share on other sites

tested with file test_file.zip

created with winrar as zip file

 

came up same error

Came back with error

path/to/zip.zip is not recognized as a valid input

 

 

 

Does my version of windows play a role in this?

windows 7 64bit (x86)

 

 

I just can't seem to get it to work on my end to unzipping the zip document to the folder created.

 

TJ

Link to post
Share on other sites

TJ,

 

Can you view the contents of your zip file with Windows explorer?

 

Can you give me your exact ui input values you used? So I can try to recreate the issue.

 

Lastly a little sample zip file please. I create mine with 7-zip.

 

Yep I am Windows 7 64bit.

 

Thanks,

Kevin

Link to post
Share on other sites
  • 2 weeks later...

TJ,

 

Update the sample bot and vbscript.

 

Added ability to turn on debug and missing zip file messages externally. No recompiling bot.

To get zip missing message create file named: zip-missing-message.dat in the directory the sample bot is.

To get debug message create file named: vbscript-debug-message.dat in the directory the sample bot is.

Sample bot is only looking for the file name. Files can be empty.

 

I have and continue to run this on my WinXP SP3 box with all the latest Microsoft patches. It runs without a issue.

 

So I am stumped as what the problem could be.

 

unzip to folder-002.ubot

 

Kevin

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...