Friday, January 27, 2006

[VBScript] Where else have I logged in on this network?

It's not so much a question for me -- I remotely log into many pcs daily as part my job, and try to leave as few tracks as possible. However, today a customer rang saying she'd lost a few important Favourites and had no backup. The best way I could think of helping her, was to locate all the machines she's logged into and see if any of the Favourites could be found.

I did find what she was looking for. Here's the code I used.

First the standard header implementing the synthetic include (derived from
Rube Goldberg Memorial Scripting Page)
StandardLibrary.vbs is getting big. 1500+ lines of code.

Next a little function for a right fill. Having needed this only once, I haven't included it in the StandardLibrary.
Now the main body of the script.

1. Check commandline to see if a username is specified.
1.1 If nothing specified, throw a fit.
2. Get an array of all the computers currently online.
2.1 No error checking here but there ought to be
3. Tell everyone what's going on.
4. Loop through the names of the online machines
4.1 Trim off the leading \\ put on by NET VIEW
4.2 Write out the name, right filled with dots
4.3 Get an array of the login profiles for the computer
4.4 Scan the array to see if contains the the username (case insensitive search)
4.4.1 If found say so with a CRLF
4.4.2 otherwise issue a CR

The calls to BeginsWith are commented out. They apply only to my situation where a company edict ensures that all desktop pc names start with PC and all laptops with LP.
The supporting library rountines are below, First GetOnLineComputers with its supporting routines, GetNetView, CaptureDOS and ReadFile
Next, BeginsWith (included for completeness sake)
Then GetLoginProfiles, plus support routine AAdd
And, finally, StrInArray.
Unfortunately, this does not run quickly. It can take ages to get through the entire list and sometimes hangs inexplicably. Your mileage may vary.

If anyone comes up with a faster way of doing this I'd be very interested.

Monday, January 23, 2006

[Euphoria] Structured Access, part 2

I knew I had it somewhere. Okay, these implement the following: BYTE, BYTES, WORD, DWORD, QWORD, ASCIIZ and PSTRING. You can pull the data one chunk at a time as per the last posting or else pull a whole set all at once.

The file versions don't work and I'm not sure why, and as I said before, I don't have the time to do anything about it.

By the way, this was written before Euphoria 2.5. In fact, possibly before 2.4 so the code may need some tweaking.

mread is like the getmem of the previous posting. memread takes a sequences of reads. I will eventually post an example (if I can find one).

(Since writing part 1, I've been in touch with CChris from
Euphoria Standard Library who has taken over the development of getmem. It's great to be able to give something back to the Euphoria community after all these years (I've been using it since version 1.5).)

Tuesday, January 17, 2006

[Euphoria] Structured Access

Late last century, in a developing part of the world, I tried writing a diskette cataloguer. It worked okay, once I'd figured out how to do all the gymnastics necessary for BIOS calls. In the process I wrote a function to access memory in a structured way. Brilliant as Euphoria sequences are, they are just that: sequences. There's little in the way of structure, unless you apply some of your own.

I've reproduced the function in its entirety below. Essentially, the code takes data from memory in a structure way, that is, in terms of BYTE, BYTES, WORD, DWORD or ASCIIZ.

An attempt was made to make the functions applicable to files. Those routines don't work, and I haven't taken the time to find out why. Good as Euphoria is, there's no Mac OS X version (so I can't use it at home) and there's no opportunity to use it at work -- Euphoria's not in the SOE. If you're interested in looking at the code, write.
As an example of how to use getmen, below is the code for GetDriveParameterTable
As an example of the BYTES parameter:
The ASCIIZ parameter is like the BYTES except it keeps working its way through memory until it encounters a binary zero and then returns everything up to that point.

From memory I remember writing a version of getmem() which received a sequence of BYTE, WORD, etc. specifications and returned the resulting sequence of results. When I find it I'll post it.

Enjoy.

Wednesday, January 11, 2006

[VBScript] A CLI framework

Here's a simple framework for building your own CLI (Command Language Interface) Keywords at this point are: quit, exit, bye, eval, echo, set and run. Below is a sample session. Now my own version adds a little to this framework by including a .vbs file full of extra symbols, procedures and classes. I've reproduced it below just so that you can see how to do a synthetic include in VBScript. Interestingly, the technique also works in HTAs. Enjoy.

[VBScript] CSV to variables using Execute

Nico wrote, on microsoft.public.scripting.vbscript:
I need ASP to read the CSV file to read lines 2 on-wards and display it back to the user for verification. Each line has aprx 8 "," that control user properties.

I am looking for each line to be displayed back to the user without the "," so they can verify and write to an access db.

All i am looking for is a simple way to read the text display to the user for acceptance before writing it back to the db.
I wrote a response but thought a fuller treatment was in order, thus the following:

Data, stored in DEMO.CSV
Then the code which does nothing other than read the file, store the data in variables for each line of data, and for effect, echoes the first and last names And here's the results of the run, taken from SciTE's output window A possible extra step would be to read the header line, strips the spaces, build the "Dim" statements and execute them as well. Or maybe, create an instance of "Scripting.Dictionary" and use that. Or ... well, there must be more than two ways to do it, even in VBScript!

Tuesday, January 10, 2006

[VBScript] Threads ... thin ones

The following is an attempt at threads in VBScript. The code owes a lot to Greg Chapman of MouseTrax Computing Solutions. There are two scripts, the first calling the second (in many instances). The means for communicating between the two is via the Volatile environment. When the script runs, Outlook flickers (don't know why).

There are comments, but the basic idea is to keep a watch over how many instances of cscript.exe there are running and while there's only so many, add more. Use the Volatile environment for semaphores and make sure there's enough delay in there to get stuff to and from Volatile (which is actually in Registry and not blazingly fast).

First the controller.
Then the controlled. There are quite a few extra useful routines in all that code, including an AADD(), and assorted WMI related routines.

I'm in the process of putting the thread functionality inside a Class so that I can change how things are done without causing drastic rewrites of the original VBScripts. I'm not entirely pleased with the Volatile environment and may end up playing with something else that can be used as a shared storage area between many programs ... like subdirectory structures.


Monday, December 19, 2005

[VBScript] Deriving user name from computer name

I found a brilliant bit of code for deriving the username from the computer name. It's found inside Matt Williams's "ManagePC v1.31" HTA. His description of the routine is as follows
This bit of code is "cheating" slightly in that all it's doing is getting the owner of the explorer.exe process. Seeing as explorer.exe only runs if a user is logged on it is a reliable (but sneaky) way of getting the logged-on user. It does, however, mean that even if a user is logged on locally or the account is a generic account, it will retrieve the correct values (WMI cannot do this).
-- Matthew Williams, ManagePC
Below is my routine, combining his code with some extra housekeeping. Of course, if no one is logged in, you get nothing. My own take on Matt's routine adds in a check to see if the computer is actually running, using ResolveIP() below:

[VBScript] Plugins

I had written a plugin architecture for one of my HTA applications. Now I discover that I can have plugins using almost any scripting language available. I found this bit of brilliance in a google search: I can now pass whatever information I like to and fro from application to plugin and back again. And if another scripting languages does something better than VBScript I can use it (provided it gives access to the volatile store).

Wednesday, December 07, 2005

[Working Again]

After a short stint on the support queue at iiNet (part-time), I'm now on contract at Department of Land Information. L1 and L2 support with a bit of scripting on the side. VBScript again, sadly.

Friday, November 04, 2005

[Pharmacy Software]

One of my clients has suggested I write pharmacy software. He has a home-grown Clipper app that does everything from Dispensing to Cash Register. I give him a hand with it from time to time. He reckons there's a market for a low-cost package which would fit the Western Australian situation better than the off-the-shelf ones now available.

So comes then the ever-present question: Closed Source, or Open Source.

No knowing a lot about how Open Source works as an income generator, I fear that there is the risk that my non-Open Source competitors may steal my ideas and woo my customers away because they have the resources to bring them (the ideas, not the customers) to the market faster than I can. Is that a valid concern?

Closed Source isn't without its problems either.

And then comes the other questions: programming language / IDE / RAD. I wonder if anyone's come up with a template for software projects in the style of Word / Excel / PowerPoint templates.

[Visual Studio 2005 Team System Beta 2]

I went to a Microsoft do yesterday and that's what they gave me (amongst other things.) Now to find a machine to install it on (only Linux, MacOSX and Win98 at home).

Eventually I want to start bidding on jobs at Get A Coder and Get a Freelancer.

Until then ... Khuda janta he.

Thursday, October 20, 2005

[VBScript] Shell and Heap Sorts

The final versions of the Shell sort and Heap sort classes. First the ShellSorter:
and then the HeapSorter


By the way, I'm unemployed again. Things might be a bit quiet around here for a while.

Saturday, October 15, 2005

[VBScript] sorting algorithms

Thanks to Dr Hans Werner Lang for his helpful comments on the sorting routines, as below:
Hi,
but there is no need to rewrite the outer loop, is it?
    for i=h to n-1
    ...

The inner loop, with the problem of the conditional And, could be written as
    do while j>=h
        if a(j-h)<=t then exit do
        ...
    loop

In my opinion, exit do should be avoided (when possible).

Regards
H.W. Lang
I've made the changes to the class as suggested but haven't posted them as yet.

[MetaCard] Starter Kit script size limit, Part 2

And if anyone was curious what happened to the MetaCard script size issue, Ken Ray said,
>I've been told, via the MetaCard list, that you have a technique for
>getting around the script size limit in MetaCard. If that's so, please
>can you tell me whence I can download the whitepaper about it.

Sorry to disappoint you, Bruce, but I don't. In fact, given that DreamCard is only $99, it seems counterproductive to attempt to get around the script size limits when you can pick up a full development environment very inexpensively.
and Geoff Canyon said
I don't recall that I wrote anything in particular. I did write an exporter for the documentation for earlier versions of Revolution, and they had a small section on dealing with the script limits in the starter kit. The basic point is to understand how to write tight code. You can insert scripts in front and back, and "start using" stacks, and use nested groups to your advantage. You can also store scripts in custom properties and use the "do" command on them.

If you ask on the mailing list, there are several people there who spent significant time working within the script limits who can probably help you with any specific issues. I bought a license early on so I don't have much practical experience.

Finally, if you're concerned about whether Rev is a good fit for what you want to do, ask on the list. People will tell you the truth. There are (many) things Rev is very good for, and (almost as many) things it isn't well suited for.
>I'm told that, sometime late last century, you wrote
>something about side-stepping the script size limit in
>the MetaCard unregistered version.
So the upshot of all this is: spend some money and stop complaining.

Thursday, October 13, 2005

[xbScript] Hooley Dooley! Move over VBScript, here comes xbScript

This is just amazing! "xbScript.dll enables xBase scripting (exactly like MS vbScript and JScript) in any MS ActiveScript compliant Host." Now I can help a friend, who has a large legacy Clipper app running in DOS under Windows, to integrate his software into the Windows environment. And he won't have to learn another language when he wants to tweak things. Hallelujah!!

[EOC] T minus 2 and counting

It's Thurday. I'm busily updating the documentation.

Friday 14 October is "The Last Day". (I wish it was THE last day, that is, the day Jesus returns.)

Of the 19 agencies I've written to, 4 have replied to say they're working on it. Looks like it's back to getting suited up and walking from agency to agency in the Perth CBD saying, "G'day, remember me? Yeah, I'm actually 3D and have feelings."

There's this disease one can get -- I get it often -- called PLOM disease: Poor Little Old Me.

Wednesday, October 12, 2005

[VBScript] Please, please, no more sorting!!

After so many tries, I had thought I was done with it. Well the virtual memory limit on my machine still stands so when the shellSort encountered an array of 1.5 million records, it failed. I could have gone ahead with getting the VM size increased but decided it was better to deal with the limitation as it stood. Who knows, the next bloke may not have much virtual memory either (though, I suppose, he's more likely to have lots more.)

I handed the job over to SORT.EXE and used the Exec method to call it. Like this:
The actual call to SortFile is what were talking about but the oSamples stuff needs some explaining. SuperContainer is a class based on the ADODB.Streams object. Interestingly I had a lot of trouble with the ReadFromFile method in ADODB.Stream. I think this had to do with it expecting Unicode but getting ASCII. When you hand a Unicode file over to SORT.EXE, it sorts it okay but changes it into ASCII. ReadFromFile tries to interpret the file as Unicode and you end up with a mess. Thus the GetFile()/Split/For Each thing in my ReadFile method.

The code for the sorting routine is:
I have a global in my stdFunctions.vbs called bDebugging. It's normally False but I can change it and get some useful feedback thereby.

The upshot of all this is that the sorting seems to be working ... but still not perfectly -- when I gave SORT.EXE a 63 Gigabyte file it didn't like it. But the likelihood of generating datasets that large is low.


[VBScript] read and write local and remote files

Check out a wonderful write up by Antonin Foller of PSTRUH Software on reading and writing files in VBScript. Note the very helpful stuff on Binary Files.

[General] Mergesort

This is a great site for algorithms, like Mergesort. A round of applause for the author, Prof. Dr. H. W. Lang.

It's mostly German language, but there are some English translations and the Java code is fairly human-language-neutral.

Tuesday, October 11, 2005

[VScript] At last, a working shell sort

Finally found a shell sort that works. The problems I had previously might have been had because of this: I converted that straight to VBScript and kept crashing because a[j-h] with a negative index would get evaluated. By using a do/loop and breaking the test up into two parts ... I got stuff to work. Here's the code. Usage is similar to that for heap sort.