Sign in to follow this  
Followers 0
barryb

VB integration

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Psalty, he could use &= to join the strings :)

Isn't that exactly what I said? What did I miss?

:)


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

Share this post


Link to post
Share on other sites

Thanks guys I will have a look at it this afternoon, I would prefer to use native AutoIt where possible rather than having to try and tack on VBS so will pursue your advice.

Cheers,

Barry

Share this post


Link to post
Share on other sites

PsaltyDS, the AutoIt version did the trick :) , going to give up on the on the fly code creation for now and get AutoIt to do the heavy work natively,

Thanks again,

Barry

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  
Followers 0