Jump to content

Make batch file run in foreground


Recommended Posts

So I have a batch file on my desktop and I need it to run in the foreground. But when starting scripts, Pulseway opens it in the background, But I want it to open in the foreground. So how would I do that?

OS: Window 10 Pro 20H2

Edited by JaydenE55
Link to comment
Share on other sites

  • 2 months later...

Did this a long time ago... This one maps a drive letter to the server for the logged in user, you can work backwards to do anything, basically you have to create a task to make it happen that runs once on demand as the local user:


$Taskname = "netuse"
$lastlogon = (New-Object -ComObject WScript.Shell).RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI\LastLoggedOnUser")

SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $Taskname /RU $lastlogon /TR "c:\maplist.bat"
start-sleep -s 1

New-Item c:\maplist.bat -ItemType "file"
Set-Content c:\maplist.bat 'net use t: "\\twdserver\Shared\SERVER - Documents" /persistent:yes'
schtasks /Run /TN $Taskname
start-sleep -s 1
schtasks /delete /tn $Taskname /f

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...