Jump to content

Put VBScript into AutoIt Script


taypatte
 Share

Recommended Posts

I wrote a VBScript to get the current machine name from SCCM. I need to use the variable that the machine name is in in an AutoIt script because I need to display that name as a label in the GUI. I can't do it all in AutoIt because it doesn't have access to the Microsoft.SMS.TSEnvironment, where the SCCM stuff is stored. I have looked at threads similar to this, but I cannot find a straight answer that works. I am also an AutoIt newbie, so this is beyond my level. Can someone at least steer me in the right direction? I would really appreciate it.

Link to comment
Share on other sites

Can you pass it in through the command line? Use your VBScript to call your AutoIt and and get it from $CmdLine[1] or something similar?

If not, write it somewhere, a text file at worst, the registry would likely be best and read it with AutoIt

Edited by seadoggie01
Forgot this wasn't StackOverflow, no inline code

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Pst your VBScript and your AutoIt script and let us see if the VBScript can be totally translated to AutoIt, more than likely it can be.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

8 hours ago, BrewManNH said:

Pst your VBScript and your AutoIt script and let us see if the VBScript can be totally translated to AutoIt, more than likely it can be.

set oTaskSequence = CreateObject("Microsoft.SMS.TSEnvironment")
computerName = oTaskSequence("_SMSTSMachineName")
WScript.Echo computerName & "=" & oTaskSequence(computerName)

Here is the VBScript. I can't do this in AutoIt because AutoIt cannot access Microsoft.SMS.TSEnvironment.

Link to comment
Share on other sites

  • Moderators

Why not? Does this not work?

$oTaskSequence = ObjCreate("Microsoft.SMS.TSEnvironment")

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

29 minutes ago, JLogan3o13 said:

Why not? Does this not work?

$oTaskSequence = ObjCreate("Microsoft.SMS.TSEnvironment")

 

It does not work. I have tried that and other ways and it seems AutoIt just can't access it for some reason. The problem with that line of code is that it doesn't actually create the object.

Link to comment
Share on other sites

try downgrading your autoit installation to version 3.12.0 as there are problems with COM objects in newer autoit versions.

 

/edited for error :/

Edited by Werty

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

  • Moderators
1 hour ago, taypatte said:

The problem with that line of code is that it doesn't actually create the object.

Which is weird, since I wrote the SCCM UDF (admittedly not updated in a couple years now). If I get a chance to get to a machine with SCCM installed, I will take a look.

Edit: Just to clarify what SCCM build are you on?

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

20 hours ago, JLogan3o13 said:

Which is weird, since I wrote the SCCM UDF (admittedly not updated in a couple years now). If I get a chance to get to a machine with SCCM installed, I will take a look.

Edit: Just to clarify what SCCM build are you on?

Yes it is very weird. I believe I'm on the 1906 build.

Link to comment
Share on other sites

On 9/23/2019 at 2:44 PM, seadoggie01 said:

Can you pass it in through the command line? Use your VBScript to call your AutoIt and and get it from $CmdLine[1] or something similar?

If not, write it somewhere, a text file at worst, the registry would likely be best and read it with AutoIt

Could you elaborate more on how to run it through the command line?

Link to comment
Share on other sites

Sure... just have the VBScript run your AutoIt script and pass the computer name as a parameter... like this:

set oTaskSequence = CreateObject("Microsoft.SMS.TSEnvironment")
computerName = oTaskSequence("_SMSTSMachineName")

Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "myAutoIt.au3 " & computerName
Set objShell = Nothing

Then, in your AutoIt Script, you can retrieve command line parameters with the $CmdLine array...

If UBound($CmdLine) > 1 Then
    Global $computerName = $CmdLine[1]
EndIf

Edit: I'm really fuzzy on VBScript, but I find this site super helpful: SS64.com

Edit 2: I can't test this code, but I think it should work... the Microsoft.SMS.TSEnvironment line throws an error for me.

Edited by seadoggie01

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

12 minutes ago, seadoggie01 said:

Sure... just have the VBScript run your AutoIt script and pass the computer name as a parameter... like this:


set oTaskSequence = CreateObject("Microsoft.SMS.TSEnvironment")
computerName = oTaskSequence("_SMSTSMachineName")

Set objShell = WScript.CreateObject ("WScript.shell")
objShell.run "myAutoIt.au3 " & computerName
Set objShell = Nothing

Then, in your AutoIt Script, you can retrieve command line parameters with the $CmdLine array...

If UBound($CmdLine) > 1 Then
    Global $computerName = $CmdLine[1]
EndIf

Edit: I'm really fuzzy on VBScript, but I find this site super helpful: SS64.com

Edit 2: I can't test this code, but I think it should work... the Microsoft.SMS.TSEnvironment line throws an error for me.

Thank you! This helps a ton. Yeah, the Microsoft.SMS.TSEnvironment only works inside the task sequence. Also, does the AutoIt script have to be .au3? I think the file I need to use needs to be .exe.

Edited by taypatte
Link to comment
Share on other sites

No problem, glad to help, even if it's the slightly cheaty way :)

No, it's better if the file is an exe, then you don't need to worry about executing vs opening the au3 file

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

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