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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...