Determine if Taskbar is running.

I control what applications are available and what applications run through group policy and logon scripts.  I have an application that I start when someone logs in that sits in the system tray.  The problem is that if the logon script tries to kick off that application before the taskbar appears, that application errors.  Is there a way I can determine, using vbscript, if the taskbar is visible?  I could then pause the script execution if necessary.  Is there a way to return the handle of the Shell_TrayWnd window to the script?  Are there programs I can run from within the script that could help me?
CousinDupreeAsked:
Who is Participating?
 
jahboiteConnect With a Mentor Commented:
I did a bit of hunting and had a little play and couldn't manage to do what I was trying to do.
But I'm not sure I was using the right data types and my scripting isn't up to much so it might be worth you looking into to see if you can succeed where I did not...

I searched out a way to declare a system API from vbscript and found:
http://ourworld.compuserve.com/homepages/Guenter_Born/WSHBazaar/WSHDynaCall.htm

where you can get a dll called dynwrap which needs regsvr32'ing
then you can call it like this:

Dim UserWrap
Dim lhWnd

Set UserWrap = CreateObject("DynamicWrapper")
UserWrap.Register "USER32.DLL", "FindWindowA", "I=ss", "f=s", "R=h"

lhWnd = UserWrap.FindWindowA("Shell_TrayWnd", null)
wscript.echo lhWnd


Unfortunately lhWnd came back as zero and my taskbar is definately showing!
0
 
jahboiteCommented:
Is it possible that you've enabled "Always wait for the network at computer startup and logon"
If you have then you could disable it and your scripts would run without waiting for the shell to start.
See http://support.microsoft.com/kb/304970 (and do the opposite)

If you've tried this already then I apologise...
0
 
CousinDupreeAuthor Commented:
First of all, there is no need to apologize for anything.  I am the one asking for help!

I'm afraid your suggestion won't work though.  New users, i.e. users who have never logged onto the computer before, will force the computer to wait for the network, regardless of how that policy setting is set.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
jahboiteCommented:
Oh.
Then have you looked into using the Win32_Process class of WMI?
0
 
CousinDupreeAuthor Commented:
I have, but I don't know what process to look for.  I thought Explorer.exe might be the one, but there is no guarantee that the taskbar is there.
0
 
CousinDupreeAuthor Commented:
When a new user logs on, Windows synchronizes everything, i.e. merges the default user profile with the new profile, sets a bunch of IE and Outlook Express settings, etc.  It appears to me that the task bar doesn't appear until the synchronization is complete - thus my question.  I know that there are applications such as Setup50.exe and ie4uinit.exe that run, but I don't know what process is kicking them off.  If I did I would just watch the process list, wait for that one to finish, and then proceed.
0
 
jahboiteCommented:
Right.  And you're looking for something more solid than the assumption that shortly after the explorer starts, the taskbar should be visible.
Something along the lines of lhWnd = FindWindow("Shell_TrayWnd", vbNullString)
0
 
jahboiteCommented:
Yes I see.  (The above two posts should have appeared in reverse order by the way folks!)
0
 
RobSampsonConnect With a Mentor Commented:
Hi jahboite and CousinDupree,

Wow jahboite, you were getting so close there I reckon!

I also did some testing, based on exactly the same this, only I found some other source code at:
http://www.stealthbot.net/board/index.php?showtopic=7577

The ONLY difference that I did was to this line:
lhWnd = UserWrap.FindWindowA("Shell_TrayWnd", null)

where instead of using null, I used an empty string: ""
which returned the handle of the task bar!  How annoying is that?!?!?!

So you basically be able to get away with something like this:

'==============
Dim UserWrap
Dim lhWnd

Set UserWrap = CreateObject("DynamicWrapper")
UserWrap.Register "user32.dll", "SetWindowPos", "i=lllllll", "f=s", "r=l"
UserWrap.Register "user32.dll", "FindWindowA", "i=ss", "f=s", "r=l"

While lhWnd = 0
      lhWnd = UserWrap.FindWindowA("Shell_TrayWnd", "")
Wend

' Now the handle has been found, you should be able to run other code below this
WScript.Echo "The handle for the System Tray is: " & lhWnd
'==============

Regards,

Rob.
0
 
RobSampsonCommented:
Oh, and just to expand on the instructions on the DynWrap.dll, download the NT version Zip file from:
http://ourworld.compuserve.com/homepages/Guenter_Born/WSHBazaar/WSHDynaCall.htm

and then just extract the DynWrap.dll file to your System32 directory (usually C:\Windows\System32), then click Start --> Run, type in:
regsvr32 c:\windows\system32\dynwrap.dll

and click OK.

Then this script should work.

Regards,

Rob.
0
 
jahboiteCommented:
Well done RobSampson!  Works for me too.
Only thing that may be of concern is that the dll will need registering on every machine on which the script is to run...
0
 
CousinDupreeAuthor Commented:
Wow, this is good stuff!  I can't thank you enough for your help on this.  I'm inclined to split the points right down the middle.  If I could, I'd give each of you 500.  Please let me know how you think I should handle this.
0
 
RobSampsonCommented:
jahboite, you are correct, this would need to be done.  I would suggest running a Computer Configuration --> Windows Settings --> Scripts --> Startup login script, which would run under the System account.  That way you should be able to copy the dynwrap.dll file to the System32 folder, then hopefully run regsvr32.....but I'm not sure yet.....

CousinDupree, we're not quite finished yet, because of this registration concern, but half / half points is fine with me.

Regards,

Rob.
0
 
RobSampsonCommented:
It seems that as a StartUp script, as this uses the local System account, does not have access to copy such a file from a network share.  If your users are local administrators of their machine, then you can use a login script to copy the file to the System32 folder, then run regsvr32 to register it.

However, if your users are not local Administrators, they cannot copy files to the System32 folder.  Therefore, as far as I know, there are two options:

1/ Use a login script to copy the file to the local C:\Temp folder (or somewhere the user can write to), then on the *next* reboot, a StartUp script could copy it from C:\Temp (checking if it exists first) to C:\Windows\System32 and then run
regsvr32 /s C:\Windows\System32\DynWrap.dll
to register it

2/ Embed a domain admin password into a VBS encoded file (which becomes VBE, using Microsoft's Script Encode), and use a login script that launches PSExec with the domain Admin credentials, copies the file, and registers it.

Any thoughts on these?

Regards,

Rob.
0
 
jahboiteCommented:
Yes Rob, your number 2/ looks the favourite.  What do you reckon CousinDupree?
I'm happy with a 50/50 split.
0
All Courses

From novice to tech pro — start learning today.