Solved

vbscript doesn't run on first logon

Posted on 2006-06-18
6
638 Views
Last Modified: 2009-07-29

This script runs with a group policy and locks the desktop down. I noticed in frequent cases that it leaves the control panel in the Start Menu either though I have it hidden in the script. When i logoff and log back on it finally disappears.
Any ideas?

Option Explicit

'Declare variables
Dim WSHShell, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, q, p, z, NN, FS
Dim itemtype, errnum
Set WSHShell = WScript.CreateObject("WScript.Shell")


b = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
b = b & "NoSetTaskbar" 'This restriction removes the Taskbar and Start Menu item from the Control Panel, and it also removes the Properties item from the Start menu context menu

d = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
d = d & "NoSimpleStartMenu" 'This restriction forces users to use the classic Windows start menu, instead of the new format introduced with Windows XP.

e = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
e = e & "NoTrayContextMenu" 'This setting removes the context menus (right click on the taskbar) for the system tray, including the Start button, Tab control, and Clock.

f = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
f = f & "NoFind" 'This restriction removes the Search feature from the Start Menu.

g = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
g = g & "NoDriveTypeAutoRun" 'Doesn't auto run CD

h = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
h = h & "NoRun" 'No Run menu

i = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
i = i & "NoSMHelp" 'No Help Menu

j = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
j = j & "NoRecentDocsMenu" 'doesn't cache recent docs menu

k = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
k = k & "StartMenuLogOff" 'no logoff

l = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
l = l & "NoCommonGroups"

m = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
m = m & "NoSetFolders" 'This restriction removes the Control Panel, Printers and Network Connection settings from the Start menu. If the Taskbar settings are also hidden it causes the Settings menu to be completely removed.

o = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
o = o & "NoDrives" 'NO C drive

p = "HKCU\Software\Policies\Microsoft\Internet Explorer\Restrictions\"
p = p & "NoBrowserContextMenu"

q = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\"
q = q & "NoDispCPL" 'This option disables the display settings control panel icon, and stops users from accessing any display settings

z = "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\"
z = z & "NoViewContextMenu" 'no right click on desktop


itemtype = "REG_DWORD"

'-------------------
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (d)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite d, 0, itemtype
End If

'-------------------
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (p)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite p, 0, itemtype
End If

'------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (k)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite k, 0, itemtype
End If

'------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (z)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite z, 0, itemtype
End If

'------------------
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (m)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite m, 0, itemtype
End If

'-------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (i)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite i, 0, itemtype
End If

'------------------
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (j)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite j, 0, itemtype
End If

'-------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (b)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite b, 0, itemtype
End If

'--------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (e)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite e, 0, itemtype
End If

'--------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (o)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite o, 0, itemtype
End If

'--------------------
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (f)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite f, 0, itemtype
End If

'---------------------
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (h)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite h, 0, itemtype
End If

'--------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (g)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite g, 0, itemtype
End If

'--------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (q)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite q, 0, itemtype
End If
'--------------------

Err.Clear
On Error Resume Next
n = WSHShell.RegRead (l)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
'Create the registry key value for NoFolderOptions with value 0
      WSHShell.RegWrite l, 0, itemtype
End If
'--------------------

'If the key is present, or was created, it is toggled
'Confirmations can be disabled by commenting out
'the two MyBox lines below


NN = 0
n = 1
a = 12
c = 181

WSHShell.RegWrite k, NN, itemtype
WSHShell.RegWrite l, n, itemtype
WSHShell.RegWrite i, n, itemtype
WSHShell.RegWrite j, n, itemtype
WSHShell.RegWrite d, n, itemtype
WSHShell.RegWrite p, n, itemtype
WSHShell.RegWrite z, n, itemtype
WSHShell.RegWrite m, n, itemtype
WSHShell.RegWrite b, n, itemtype
WSHShell.RegWrite e, n, itemtype
WSHShell.RegWrite o, a, itemtype
WSHShell.RegWrite f, n, itemtype
WSHShell.RegWrite g, c, itemtype
WSHShell.RegWrite h, n, itemtype
WSHShell.RegWrite q, n, itemtype
WSHShell.RegWrite m, n, itemtype
0
Comment
Question by:Fubyou
6 Comments
 
LVL 11

Accepted Solution

by:
pratap_r earned 400 total points
ID: 16932257
This happens when there is a race condition between explorer.exe(shell) and your script. Try killing explorer.exe at the end of your script and restarting it.
0
 
LVL 52

Assisted Solution

by:Julian Hansen
Julian Hansen earned 50 total points
ID: 16932428
Just a thought ...

One thing you could try is to create a key in the user registry to run the vbscript as your shell
HKCU/Software/Microsoft/Windows NT/CurrentVersion/Winlogon/Shell=yourscript.vbs

The last thing your script does is to start explorer.

Explorer checks the contents of the same key but in the Machine Registry - if it finds itself there and no other instances of explorer are running it will start in shell mode.

This should allow your script to finish running before the shell starts.

0
 
LVL 11

Expert Comment

by:pratap_r
ID: 16932458
thats a good hack :), just make sure the script doesn't fail in the middle, otherwise the user will end up without a shell.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 52

Expert Comment

by:Julian Hansen
ID: 16932528
you can get around that too - put in an app that first statrs the script - waits for it to finish - then starts the shell.

We have done this quite a bit for getting around explorer induced problems.
0
 

Author Comment

by:Fubyou
ID: 16942406
what are the lines to kill explorer.exe not that I couldn't google it, of course..
to lazy
0
 
LVL 2

Assisted Solution

by:TiwariVikas
TiwariVikas earned 50 total points
ID: 17018251
Try the following code to kill explorer.exe...

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = 'Explorer.exe'")

For Each objProcess in colProcessList
    objProcess.Terminate()
Next

Regards,
Vikas.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
strDist challenge 35 97
topping3 challenge 14 70
word0 challenge 3 78
Programatically extract date from website 8 67
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now