-1

The below script is distributed widely, however I cannot seem to run wshShell.Run(loginscript) silently using wshShell.Run "loginscript",0, TRUE. It simply does not run that portion with no error.

Dim wshShell
Dim wshProcess
Dim domain, username, dc

Set objNet = CreateObject("WScript.NetWork") 
Set wshShell = CreateObject("Wscript.Shell")
Set wshProcess = wshShell.Environment("Process")

Domain = objNet.UserDomain
UserName = objNet.UserName
DC = wshProcess("LogonServer")

Set UserObj = GetObject("WinNT://" & domain & "/" & username)

loginScript = DC & "\netlogon\" & UserObj.LoginScript

On Error Resume Next
wshShell.Run(loginscript)

Set UserObj = Nothing
Set wshProcess = Nothing
Set wshShell = Nothing
Set objNet = Nothing

My9to5
  • 93
  • 8
  • @user692942 ```set objShell = Wscript.CreateObject(loginscript) objShell.Run "loginscript", 0, True``` I may have got the syntax wrong, but it did not work for me – My9to5 Mar 17 '23 at 18:06
  • 1
    In which case, there is another issue as this does work. Unfortunately, there isn't much for us to go on. – user692942 Mar 17 '23 at 19:27

1 Answers1

0

My initial issue was getting the logon script for users without the Powershell AD module installed - since users dont have it installed. Below is a Powershell accelerator (whatever that is).

$user = ((Get-Ciminstance -ClassName Win32_ComputerSystem).Username).Split('\')[1]
$script = ([adsisearcher]"(&(objectClass=person)(objectClass=user)(SamAccountName=$user))").FindAll().Properties.scriptpath

start-process \\[DC]\NETLOGON\$script -WindowStyle Hidden -ErrorAction Continue```
My9to5
  • 93
  • 8