Jump to content
Sign in to follow this  
dunk6

VBScript to AutoIt Errors!

Recommended Posts

dunk6

I have this code running using VBsEdit

TargetFolder = "C:\temp" 
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items
For i = 0 to colItems.Count - 1
    colItems.Item(i).InvokeVerbEx("Open")
Next

When i try to run it using AutoIt, i do this:

Option Explicit 

Dim oShell
Dim oAutoIt

Set oShell = WScript.CreateObject("WScript.Shell")
Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

Dim TargetFolder
set TargetFolder = "C:\Archive" ;//ERROR HERE

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items
For i = 0 to colItems.Count - 1
    colItems.Item(i).InvokeVerbEx("Open")
Next

WScript.Quit

I receive error at

TargetFolder = "C:\Archive"

Can anybody tell me what i did wrong? thank you

Share this post


Link to post
Share on other sites
Inverted

There is no "set" command in AutoIt, you assign values to variables like this :

$ex1 = 45

So put a dollar sign in front of all variables.

Edited by Inverted

Share this post


Link to post
Share on other sites
FuryCell

Are you trying to run as an AutoIt script, or are you trying to use the com object? If your trying to run it as an AutoIt Script use this.

$TargetFolder = "C:\temp"
$objShell = ObjCreate("Shell.Application")
$objFolder = $objShell.Namespace($TargetFolder)
$colItems = $objFolder.Items
For $i = 0 to $colItems.Count - 1
    $colItems.Item($i).InvokeVerbEx("Open")
Next
Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites
FuryCell

It can also be done without COM using AutoIt functions like this:

#Include<File.au3>
$TargetFolder = "C:\temp"
$Files=_FileListToArray($TargetFolder)
For $i = 1 to $Files[0]
    ShellExecute($TargetFolder&"\"&$Files[$i],default,default,"Open")
Next

Edit: Also your VBS code appears to be flawed. It does not appear to have anything to do with AutoIt. This works fine.

TargetFolder = "C:\Archive" 
Set oAutoIt = WScript.CreateObject("AutoItX3.Control")

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items
For i = 0 to colItems.Count - 1
    colItems.Item(i).InvokeVerbEx("Open")
Next
Edited by P5ych0Gigabyte

HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code.

Share this post


Link to post
Share on other sites
jvanegmond

Agh, it's an AutoItX error. (Edit: Not really, but.. It's not a VBScript to AutoIt conversion error). That was confusing.

Edited by Manadar

Share this post


Link to post
Share on other sites
dunk6

Sorry for the confusion, when i go tru again, this code is called AutoItX. :)

Share this post


Link to post
Share on other sites
dunk6

the error fix, but new problem arised. Sorry really nd ur guyz help again.

What i want the program do:

1) read source, destination, folder path and password from textfile

2) function execute() -> select from context menu and do some execution and new file *.pac will created.

3) function moveToDest() ->once execution finish, move all *.pac files to destination folder.

ERROR here: after finish no.2, the operation stop and cause this error

remote server has been paused or is in the process of been startup.

runtime error: permission is denied.

What does it mean. How to fix this?

...
Call Execute()
oAutoIt.Sleep(1000)
Call moveToDest() //ERROR HERE, AFTER FINISH CALL Encrypt(), IT SEEMS IT CANNOT INVOKE THIS FUNCTION

'Encrypt the content in the source folder
Sub Execute()   
    Dim objShell: Set objShell = CreateObject("Shell.Application")
    Dim objFolder : Set objFolder = objShell.Namespace(source) 
    Dim colItems: Set colItems = objFolder.Items
    Dim i
    For i = 0 to colItems.Count - 1
        colItems.Item(i).InvokeVerbEx("Encrypt")
        oAutoIt.Sleep(500)
        oAutoIt.Send("!w")
        oAutoIt.Send("{TAB}")
        oAutoIt.Send(pass)
        oAutoIt.Send("{TAB}")
        oAutoIt.Send(pass)
        oAutoIt.Send("{ENTER}")
        'oAutoIt.Sleep(500)
    Next
    
End Sub

'Once the file being executed, move the file to destination folder  
'move the .pac into dest folder
Sub moveToDest()
    dim newfolder
    Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
    If  Not filesys.FolderExists(dir) Then
       newfolder = objFSO.CreateFolder (dir)
       WScript.Echo "A new folder '" & newfolder & "' has been created" 
    End If
    objFSO.MoveFile source & "*.pac" , dest

End Sub
WScript.Quit

Share this post


Link to post
Share on other sites
jvanegmond

By the way, I have never used VBS in my life but a quick Google said that the Set command is used for assigning a object to a variable (possibly creating an instance of the class). A string is not an object..

Dim TargetFolder

TargetFolder = "C:\Archive" ;//Fix3d

Share this post


Link to post
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
Sign in to follow this  

×