Real Software Forums
http://forums.realsoftware.com/

VBScript
http://forums.realsoftware.com/viewtopic.php?f=6&t=42802
Page 1 of 1

Author:  shaggymac [ Tue Feb 21, 2012 9:54 am ]
Post subject:  VBScript

I want to dynamically create a VBScript and run it.

How do I execute VBScript?

Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\Server\PrinterName"
WScript.Sleep 200
objNetwork.SetDefaultPrinter "\\Server\PrinterName"

Author:  shaggymac [ Tue Feb 21, 2012 9:55 am ]
Post subject:  Re: VBScript

If possible, I'd like to not have to run the code outside the app. (meaning If possible I don't want to create a VBS file and then execute the VBS file from a Shell command)

Author:  frankvanolffen [ Tue Feb 28, 2012 8:56 pm ]
Post subject:  Re: VBScript

shaggymac wrote:
I want to dynamically create a VBScript and run it.

How do I execute VBScript?

Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\Server\PrinterName"
WScript.Sleep 200
objNetwork.SetDefaultPrinter "\\Server\PrinterName"


You know that this is a real basis Forum???????

I hope that MS has his one forum!

Author:  shaggymac [ Wed Feb 29, 2012 9:25 am ]
Post subject:  Re: VBScript

Well I think this maybe a RB issue because I know the code runs if I type it into a Text Editor and run it.

When I generate the code from Real Basic, the code doesn't execute.

Dim Documents as FolderItem = SpecialFolder.Documents
Dim s as New Shell
Dim cmd as String

If Documents <> nil then
Dim f as FolderItem = Documents.Child("InstallPrinter.vbs")
If f <> nil then
Try
//TextOutputStream.Create raises an IOException if it can't open the file for some reason.
Dim t as TextOutputStream = TextOutputStream.Create(f)
t.WriteLine ConvertEncoding("Set objNetwork = CreateObject(""WScript.Network"")", Encodings.WindowsANSI)
t.WriteLine ConvertEncoding("objNetwork.AddWindowsPrinterConnection ""\\Server\" + PrinterLabelText.Text.Trim + """", Encodings.WindowsANSI)
t.WriteLine ConvertEncoding("WScript.Sleep 200", Encodings.WindowsANSI)
t.WriteLine ConvertEncoding("objNetwork.SetDefaultPrinter ""\\Server\" + PrinterLabelText.Text.Trim + """", Encodings.WindowsANSI)
//t.WriteLine ConvertEncoding(PrinterLabelText.Text.Trim, Encodings.WindowsANSI)
t = nil
cmd = f.AbsolutePath
s.execute "wscript " + cmd
Catch err as IOException
//handle
End try
End if
End if


The code doesn't run. When I try running out of REAL Basic, I get an error saying "The environment is incorrect"

Author:  shaggymac [ Wed Feb 29, 2012 9:42 am ]
Post subject:  Re: VBScript

When I run within REALBasic, I see (in debugger) that my Shell times out

Author:  DaveS [ Wed Feb 29, 2012 9:48 am ]
Post subject:  Re: VBScript

try chaning the SHELL.MODE?

Author:  shaggymac [ Wed Feb 29, 2012 9:52 am ]
Post subject:  Re: VBScript

Change to what? Interactive? Synchronous?

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/