Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Dec 12, 2019 12:37 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: VBScript
PostPosted: Tue Feb 21, 2012 9:54 am 
Offline

Joined: Fri Feb 29, 2008 5:25 pm
Posts: 557
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"

_________________
http://www.mupromo.com/?ref=4850
Support Indie Developers and Buy Their Products!


Top
 Profile  
Reply with quote  
 Post subject: Re: VBScript
PostPosted: Tue Feb 21, 2012 9:55 am 
Offline

Joined: Fri Feb 29, 2008 5:25 pm
Posts: 557
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)

_________________
http://www.mupromo.com/?ref=4850
Support Indie Developers and Buy Their Products!


Top
 Profile  
Reply with quote  
 Post subject: Re: VBScript
PostPosted: Tue Feb 28, 2012 8:56 pm 
Offline

Joined: Wed Mar 26, 2008 6:48 pm
Posts: 76
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: VBScript
PostPosted: Wed Feb 29, 2012 9:25 am 
Offline

Joined: Fri Feb 29, 2008 5:25 pm
Posts: 557
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"

_________________
http://www.mupromo.com/?ref=4850
Support Indie Developers and Buy Their Products!


Top
 Profile  
Reply with quote  
 Post subject: Re: VBScript
PostPosted: Wed Feb 29, 2012 9:42 am 
Offline

Joined: Fri Feb 29, 2008 5:25 pm
Posts: 557
When I run within REALBasic, I see (in debugger) that my Shell times out

_________________
http://www.mupromo.com/?ref=4850
Support Indie Developers and Buy Their Products!


Top
 Profile  
Reply with quote  
 Post subject: Re: VBScript
PostPosted: Wed Feb 29, 2012 9:48 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
try chaning the SHELL.MODE?

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: VBScript
PostPosted: Wed Feb 29, 2012 9:52 am 
Offline

Joined: Fri Feb 29, 2008 5:25 pm
Posts: 557
Change to what? Interactive? Synchronous?

_________________
http://www.mupromo.com/?ref=4850
Support Indie Developers and Buy Their Products!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group