Jump to content

VBScript to AutoIt Errors!


dunk6
 Share

Recommended Posts

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

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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