Jump to content

VBscript on your Smartphone!


Guest chucky.egg

Recommended Posts

Guest chucky.egg

Much as I hate to credit Jacek with anything, he has found this thing which could be pretty cool.

Version 2.4.5.3 (March 2005):

...

- Special edition for Smartphone 2003 and later has been added with Micro Script Host designed for smartphone user interface.

I haven't been playing with it for very long, but being able to use VBscripts opens up all sorts of options.

newObjects:

http://www.newobjects.com/product.asp?Category=63

msmobiles:

http://www.msmoblies.com/news.php/3675.html

Link to comment
Share on other sites

Guest markgamber
Much as I hate to credit Jacek with anything, he has found this thing which could be pretty cool.

I haven't been playing with it for very long, but being able to use VBscripts opens up all sorts of options.

newObjects:

http://www.newobjects.com/product.asp?Category=63

msmobiles:

http://www.msmoblies.com/news.php/3675.html

<{POST_SNAPBACK}>

Nice find! This might be something worth playing with. NS Basic is...errr....basically a wrapper around the VBScript library on larger CE boxes. Maybe this works in kind of the same manner?

Let's count the seconds before Jackhole shows up screaming about imposters or whatever the rant du jour happens to be. :-D

Link to comment
Share on other sites

Guest chucky.egg

All sorts.

I'm trying to write a script to download the weather map for my area from the BBC website.

If/When I get it working I will be able to schedule the download using xBar, and potentially use the Photo Plugin to make a homescreen that has the weather map embedded in it.

But there are loads of things you could do with it... one of them is to copy files to the phone's Windows folder at startup, which is something some people have been after for a while I think

Link to comment
Share on other sites

Guest drblow

Em ... all that sounds really wow, but it's all a bit over my head! :oops:

Is this the kind of thing thats easy to pick up? Can somebody post any sample bits of code?

Link to comment
Share on other sites

Guest chucky.egg

I'd love to, but so far NONE of my scripts are working! :oops:

I'll have to go back to the developer because it really should be working!

Set sf = Host.CreateObject("newObjects.utilctls.SFMain")

b = sf.FolderExists("\Storage Card\Sprite Backups")

if not b then set dir = sf.CreateDirectory("\Storage Card\Sprite Backups")

cpy = sf.CopyFile("\Storage Card\HTC_2005-03-08.pbf","\Storage Card\Sprite Backups")

del = sf.DeleteFile("\Storage Card\HTC_2005-03-08.pbf", True)

What it does:

Create the SFMain object, for access to the functions

Test to see if a folder exists

If it does NOT exist then create it

---All OK so far, but this is where it gives up:

Copy all the Sprite backup files from the root of my SD card to a sub-directory

Del the Sprite files from the root directory

[EDIT]

BTW the file specified in that code was part of me testing this thing. If the Copyfile function works you can specify /Storage Card/*.pbf to copy all the Sprite backups.

Also note that the DeleteFile function does work (although the script stalls at the CopyFile line). If you were to remove the CopyFile line then it will delete the file specified in the DeleteFile line - so be careful!

[/EDIT]

Edited by chucky.egg
Link to comment
Share on other sites

Guest sunoke
I'd love to, but so far NONE of my scripts are working! :oops:

I'll have to go back to the developer because it really should be working!

Set sf = Host.CreateObject("newObjects.utilctls.SFMain")

b = sf.FolderExists("\Storage Card\Sprite Backups")

if not b then set dir = sf.CreateDirectory("\Storage Card\Sprite Backups")

cpy = sf.CopyFile("\Storage Card\HTC_2005-03-08.pbf","\Storage Card\Sprite Backups")

del = sf.DeleteFile("\Storage Card\HTC_2005-03-08.pbf", True)
First of: IANAL, in this context: I am not a vb programmer... but I'd try something like this:
// the file(s) to be copied

Source = "\Storage Card\HTC_2005-03-08.pbf"

// the destination directory for the file(s)

Destination = "\Storage Card\Sprite Backups"


// create the object for accessing the filesystem

Set sf = Host.CreateObject("newObjects.utilctls.SFMain")


// check if the destination directory exists and if not create it

if not sf.FolderExists("Destination") then sf.CreateDirectory("Destination")

// copy the file

sf.CopyFile("Source","Destination")

// delete the file

sf.DeleteFile("Source", True)

BTW: if this does not work, what are the error messages you get?

Link to comment
Share on other sites

Guest markgamber
I'd love to, but so far NONE of my scripts are working! :oops:

I'll have to go back to the developer because it really should be working!

Set sf = Host.CreateObject("newObjects.utilctls.SFMain")

b = sf.FolderExists("\Storage Card\Sprite Backups")

if not b then set dir = sf.CreateDirectory("\Storage Card\Sprite Backups")

cpy = sf.CopyFile("\Storage Card\HTC_2005-03-08.pbf","\Storage Card\Sprite Backups")

del = sf.DeleteFile("\Storage Card\HTC_2005-03-08.pbf", True)

What it does:

Create the SFMain object, for access to the functions

Test to see if a folder exists

If it does NOT exist then create it

---All OK so far, but this is where it gives up:

Copy all the Sprite backup files from the root of my SD card to a sub-directory

Del the Sprite files from the root directory

[EDIT]

BTW the file specified in that code was part of me testing this thing.  If the Copyfile function works you can specify /Storage Card/*.pbf to copy all the Sprite backups.

Also note that the DeleteFile function does work (although the script stalls at the CopyFile line).  If you were to remove the CopyFile line then it will delete the file specified in the DeleteFile line - so be careful!

[/EDIT]

<{POST_SNAPBACK}>

You've got to specify a full filename as the target of the CopyFile() call. For example:

Set sf = Host.CreateObject("newObjects.utilctls.SFMain")

b = sf.FolderExists("\Storage Card\backup")

if not b then set dir = sf.CreateDirectory("\Storage Card\backup")

cpy = sf.CopyFile("\Storage Card\test.vbs","\Storage Card\backup\test.vbs")

does work whereas

cpy = sf.CopyFile("\Storage Card\test.vbs","\Storage Card\backup")

does not. Functions like these are most likely just thin wrappers around the API functions so you can always look them up on msdn.microsoft.com and see if the MS docs differ from or expand on the object docs.

Edited by markgamber
Link to comment
Share on other sites

Guest chucky.egg

OMG!

If that work's I'll marry you!

Subject to a £10m dowry

[EDIT]

OK, that works!

But... before you get to consumate this...

How do I get it to work with wildcards?

If I specify a destination filename it just copies each file in turn onto that file, and if I specify a *.pbf or I don't specify one at all it just fails

[/EDIT]

Edited by chucky.egg
Link to comment
Share on other sites

Guest markgamber
OMG!

If that work's I'll marry you!

Subject to a £10m dowry

[EDIT]

OK, that works!

But... before you get to consumate this...

How do I get it to work with wildcards?

If I specify a destination filename it just copies each file in turn onto that file, and if I specify a *.pbf or I don't specify one at all it just fails

[/EDIT]

<{POST_SNAPBACK}>

API functions don't work with wildcards but there are objects used to manipulate directory contents. An example:

Set sf = Host.CreateObject("newObjects.utilctls.SFMain")

set fout = sf.CreateFile( "\Storage Card\test.txt" )

fout.WriteText "Dir listing:" + Chr(13), 1

set dir = sf.OpenDirectory( "\Storage Card\Source" )

set c = dir.contents

for each i in c

fout.WriteText i.name, 1

next

fout.Close

set sf = nothing

The above code creates a text file so you can see what's going on. Then it opens the directory "\Storage Card\Source" which creates an SFStorage object (dir). The contents property of that object returns a collection of SFInfo objects ( c ), each of which (i) represents a file. As each SFInfo object is retrieved from the collection in the for each loop, it's name property is written out to the text file. All you should have to do to copy files, for example, would be something like:

e = CopyFile( "\Storage Card\Source\" + i.name, "\Storage Card\Dest\" + i.name )

I'm not claiming that will work as-is, it might require some variable manipulation so the types are the same, but hopefully you get the idea.

Note that OpenDirectory does NOT take a wildcard, either. You can't do

set dir = sf.OpenDirectory( "\Storage\Stuff\*.txt" )

Instead, you always get a collection of all files and have to figure out which you want to deal with and which you don't via code.

Oh....no offense but I'll pass on the marriage. I think my wife would probably object and you know how those Irish can be. ;-) And one last note just for future reference...the E200 does NOT appear to have vbscript.dll installed. To run anything on these (and probably other) devices, you'll need to include and register that DLL which is available by itself from the newobjects.com site. I forget the URL offhand but they have it in the docs.

Edited by markgamber
Link to comment
Share on other sites

Guest chucky.egg

Well thanks for the advice, even if you don't wanna get hitched! :D

I'm off to play and see if I can get this to do anything remotely useful!

Link to comment
Share on other sites

Guest markgamber
Well thanks for the advice, even if you don't wanna get hitched! :D

I'm off to play and see if I can get this to do anything remotely useful!

<{POST_SNAPBACK}>

Just FYI, here's some example code that does work. It gets a directory listing for \Storage Card\Source and moves all the files to \Storage Card\Backup. As it runs, it displays each file's source and destination filenames, the position of a "." in the filename and the extension of the filename. Note the complete lack of error checking and assumption that there's only one "." in each filename which indicates the extension....bad assumptions but this is only a display model.

Set sf = Host.CreateObject("newObjects.utilctls.SFMain")

Host.Clear

Host.WriteLine "Directory Listing"

set dir = sf.OpenDirectory( "\Storage Card\Source" )

set c = dir.contents

for each i in c

s = "\Storage Card\Source\" + i.name

d = "\Storage Card\Backup\" + i.name

Host.WriteLine s

Host.WriteLine d

Host.WriteLine InStr( s, "." )

Host.WriteLine Mid( s, InStr( s, "." ) + 1 )

sf.CopyFile s, d

sf.DeleteFile s

next

set sf = nothing

An example of looking for specific file types:

for each i in c

' Use ONLY filename and work from end to start looking for extension

iExt = InStrRev( i.name, "." )

' If an extension separater was found...

if iExt > 0 then

' Pull extension from filename

sExt = Mid( i.name, iExt + 1 )

' If it's a text file, display the filename

if sExt = "txt" then

Host.WriteLine "\Storage Card\Source\" + i.name

end if

end if

next

set sf = nothing

Edited by markgamber
Link to comment
Share on other sites

Guest chucky.egg

You're a useful chap to know!

I've not had time to play with this as much as I'd like, but I'll try over the weekend.

Thanks for all your examples!

Link to comment
Share on other sites

Guest influenz

Hi..

At the risk of dumbing this down a bit !

Having investigated this for a while, I'm sure this is going to be really useful, thing is, I think I've fallen at the first hurdle..

This my aim..

On my c500 I would like to run a .vbs file (which I already have) at startup (i presume placing it in the start up folder will acheive this bit?). Problem is I'm a bit confused as to how i can get vb enabled.!

I've tried the smartphone downloads from the link in the first post but these won't allow me to install on the phone, saying they are made for a different version. Maybe I am downloading the wrong things ?

My wild-goose-chase has also led me to download the wm2003 sdk and the vbscript.dll (which I'm sure has something to do with it but am darned if i know how to register it!!?)

I figure you guys have already gone through this (well, the correct) process so hopefully you can give me a rolling start here !!

Thanks

;-]

Link to comment
Share on other sites

Guest chucky.egg

You need to download the Smartphone-specific newObjects MicroHost bit, and the VBscript.dll

Smartphone-specific newObjects MicroHost:

http://www.newobjects.com/downloads/axpack1/spn2003.zip

VBScript.dll

http://www.newobjects.com/downloads/axpack1/vbscript.dll

Assuming you've now got those bits you unzip them and then copy the files to your phone. I've put mine in / Storage Card / MicroHost and created a shortcut to MicroHost.exe in the Start Menu

Then, on the phone, run MicroHost. I can't remember the menus but it goes something like this: you want the right softkey, then "Tools", then "Register DLLs". Register all 4 of the DLLs (you might not need them all, but there's no harm in registering them anyway).

AFAIK you can't just run the VBS file on it's own. You need to create a link something like this: /storage card/microhost/microhost.exe scriptfile.vbs

Share your VBS, and (when I get some time) I'll post some here too.

Link to comment
Share on other sites

Guest influenz

Excellent.. Thanks..

MicroHost and vbscript installed and my vbs file runs in microhost no problems...

This is what I went with btw, to copy a couple of files to \windows (inspired by posts above!) . . .

File1 = "\Storage\Application Data\ToCopy\root.cpl.xml"

File2 = "\Storage\Application Data\ToCopy\sounds2.cpl.xml"

Copy1 = "\Windows\root.cpl.xml"

Copy2 = "\Windows\sounds2.cpl.xml"

Set sf = Host.CreateObject("newObjects.utilctls.SFMain")

go1 = sf.CopyFile(File1,Copy1)

go2 = sf.CopyFile(File2,Copy2)

Now tho i feel a little more hand-holding is required !

I need to create the shortcut for the startup folder. I started with a working link to nwmicrohost.exe but i just can't get the scriptfile parameter to work so it runs the vbs. I've tried every variation of / and \ and " and ' but I just can't get it.

These are the relevant paths..

"\Storage\Program Files\MicroHost\nwmicrohost.exe"

"\Storage\Application Data\ToCopy\AutoCopy.vbs"

Any help appreciated..

;-]

Link to comment
Share on other sites

Guest chucky.egg

I haven't got to that stage yet, but what I had expected to do was...

Create a shortcut to microhost.exe

Edit the shortcut in Notepad or similar and add the path to the VBS

If you create a shortcut and open it in Notepad what you see is:

55#"\Storage Card\Program Files\MicorHost\nwmicrohost.exe"
So I would guess you either need:
55#"\Storage\Program Files\MicroHost\nwmicrohost.exe" "\Storage\Application Data\ToCopy\AutoCopy.vbs"
Or...
55#"\Storage\Program Files\MicroHost\nwmicrohost.exe \Storage\Application Data\ToCopy\AutoCopy.vbs"

There are some notes on how to call scripts in the MicroHost readme

Edited by chucky.egg
Link to comment
Share on other sites

Guest influenz

YES !

I'm up and running now ;-]

This is my shorcut...

202#"\Storage\Program Files\MicroHost\nwmicrohost.exe" "\Storage\Application Data\ToCopy\AutoCopy.vbs"

The mistake i'd been making was keeping both paths inside one set of double quotes like in your second suggestion. Thought i'd tried everything!

So, by putting this shortcut in startup i am now succesfully copying my files over to \windows seemlessly at start up.. I can see a lot more potential here now the vbs is working.

Thanks for your help chucky, you's a star !

;-]

Link to comment
Share on other sites

Guest chucky.egg

Do you know what the number at the start of the text signifies?

Could it be a sequential number for the shortcut perhaps?

Have you tried replacing the number with another number?

If we can work out if it's relevant then we could build up a selection of scripts and shortcuts that people can download, install and run without too much tweaking required.

Link to comment
Share on other sites

Guest influenz

I had gathered that this number was used by the start menu and that it should be unique. This is why I started at 201 to avoid any others.

However it does seem that using the same number in more than one shortcut makes no odds (although the low numbers may be reserved for the system shortcuts??). The only problem I've had has been omitting the number, which makes the shortcut invalid so I guess it's maybe used to check the format is valid ??

When apps are installed on the phone it appears that the next valid number is used.

Basically though it looks as if using the same number isn't a problem and that a standard set of shortcuts shouldn't effect existing shortcuts.

I'm sure there is a good reason/explanation for these numbers but it seems we can use them for our intended purpose without messing anything else up !!

have you had a chance to try much out scripts wise ?

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.