Jump to content

VB integration


barryb
 Share

Recommended Posts

Hi,

New to the forum and I am stuck on a simple script, I searched for some answers which got me this far, and I can do what I'm atttempting from VBS.

Below is the code that I'm trying to use to set the Directory attributed to hidden

$VBS='on error resume next'
$VBS=$VBS&@CRLF&'Set objFSO = CreateObject("Scripting.FileSystemObject")'
$VBS=$VBS&@CRLF&'Set objFolder = objFSO.GetFolder("C:\Documents and Settings\Default User")'
$VBS=$VBS&@CRLF&'If objFolder.Attributes = objFolder.Attributes AND 2 Then'
$VBS=$VBS&@CRLF&'objFolder.Attributes = objFolder.Attributes XOR 2'
$VBS=$VBS&@CRLF&'End If'
$vbscript = ObjCreate("ScriptControl")
$vbscript.language="vbscript"
$vbscript.addcode($VBS)
$VBOUT = $vbscript.run("test")

The error occurs on the last line that attempts to run the code :) with the discription:

The requested action with this object has failed.

Which I take to mean it cannot create the script control?

Any help appreciated as I try to pick up AutoIt :)

Thanks,

Barry

Edited by barryb
Link to comment
Share on other sites

Hi,

New to the forum and I am stuck on a simple script, I searched for some answers which got me this far, and I can do what I'm atttempting from VBS.

Below is the code that I'm trying to use to set the Directory attributed to hidden

$VBS='on error resume next'
$VBS=$VBS&@CRLF&'Set objFSO = CreateObject("Scripting.FileSystemObject")'
$VBS=$VBS&@CRLF&'Set objFolder = objFSO.GetFolder("C:\Documents and Settings\Default User")'
$VBS=$VBS&@CRLF&'If objFolder.Attributes = objFolder.Attributes AND 2 Then'
$VBS=$VBS&@CRLF&'objFolder.Attributes = objFolder.Attributes XOR 2'
$VBS=$VBS&@CRLF&'End If'
$vbscript = ObjCreate("ScriptControl")
$vbscript.language="vbscript"
$vbscript.addcode($VBS)
$VBOUT = $vbscript.run("test")

The error occurs on the last line that attempts to run the code o:) with the discription:

The requested action with this object has failed.

Which I take to mean it cannot create the script control?

Any help appreciated as I try to pick up AutoIt ;)

Thanks,

Barry

The lines you are adding are overwriting the variable. Use the append operator: &=
$VBS &= $VBS & @CRLF & 'Set objFSO = CreateObject("Scripting.FileSystemObject")'

And leave the whitespace in your code! You don't get any points for saving pixels on the screen by making your code hard to read. :)

P.S. That should translate easily to native AutoIt. but it didn't work when I tried it. Probably easy to fix though, I don't have time right now:

; Demo, toggles hidden attribute on/off each time it is run
$objFSO = ObjCreate("Scripting.FileSystemObject")
$objFolder = $objFSO.GetFolder("C:\Temp\Testing")
If BitAND($objFolder.Attributes, 0x2) Then
   ; Hidden is currently set, clear it
    $objFolder.Attributes = BitAND($objFolder.Attributes , 0xFFFD)
Else
; Hidden is currently clear, set it
    $objFolder.Attributes = BitOR($objFolder.Attributes , 0x2)
EndIf

:)

Edit: Fixed the AutoIt native example.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...