Reconnecting to a Mapped Drive after Server Restart from within PowerShell Script - windows

I have a PowerShell v1 script that connects to a remote server via a mapped drive and moves files back and forth the remote server is identified by drive number "M" and also by UNC path REMOTESERVER\DATA:
(M:) \\REMOTESERVER\DATA
When the remote server reboots, I think that I am screwed because now the mapped drive will be inaccessible by the script.
The issue is not when the mapped drive actually disappears, it is that after reboot, authentication is needed and Windows apparently will not remember that.
How is this situation handled programmatically from within a PowerShell script?
Is there a way to reconnect to the mapped drive by writing some PowerShell code?
Just curious how this is accomplished?

Related

WinAPI: How can I list shares connected by a UNC Path

Using a UNC path such as \\1.2.3.4\drive\dir\myfile.txt I can access files on a remote machine.
I can make a connection using WNetAddConnection2 programatically
or I can just type \\1.2.3.4\ in the explorer address bar, and then Windows will prompt me for user credentials etc.
How can I list the UNC drives that the local machine is connected to for the current user?
I tried this example using WNetEnumResource - it lists nothing I find useful.
I also found this example using NetShareEnum, but it seems only to list who is connected to a specified remote machine.
I want to list all UNC drives that the local machine is connected to (which must not have necessarily have a local drive letter).
How can that be done?

Get PuTTY sessions from Windows folder

I have my hard drive from my old workstation, I did not export the PuTTY session from my old machine. I am in a situation that I am not able to boot from it, but I have it as a slave drive.
Is there any way I can scavenge the PuTTY sessions from that hard drive?
The PuTTY sessions are stored in Windows registry in key
HKEY_CURRENT_USER\SOFTWARE\SimonTatham\PuTTY
If you have a raw file system access only, you have to use some tool that can decode the HKEY_CURRENT_USER registry file C:\Users\username\ntuser.dat.
One freeware tool that can do this is MiTeC Windows Registry Recovery.
For details on the process see my guide How do I transfer my settings to another computer, when source computer is not running anymore?
The guide is for transferring settings of WinSCP client, but will work for PuTTY too. Just substitute key path Software/Martin Prikryl/WinSCP 2 with Software/SimonTatham/PuTTY.

Excel cannot see Windows mapped drive when running under a service

I have an application that runs as a service. This application allows the user to connect and starts a subprocess under the user's windows account. In other words, mydomain\john connects to the service via TCP and says "launch" which starts a process on windows running under mydomain\john account.
Next, this subprocess is able to map drive T: using net use command. Then the process can run a VB script living on the mapped drive T:. No trouble so far. the problem arises when this VB script tries to run Excel using "createObject".
After setting DCOM launch settings with DCOMCNFG and creating the missing "Desktop" folder in the systemprofile folder, I still cannot get this to work. Oddly, if run my vb script and feed Excel a UNC path \fileserver\share1 rather than T:\ the script works.
Does anyone know why Excel would fail to access the T:\ mapping but have no issue with the UNC path?

How do I list files with edit locks on a network drive using a shell and associated tools?

How do I list files with edit locks on a network drive using a shell and associated tools?
I think net file has to be run on the server, and I'm looking to do this from any box on the drive.
"Display all the open shared files on a server and the lock-id NET FILE
Close a shared file (disconnect other users and remove file locks) NET FILE id /CLOSE"
And this was tested on an xp workstation. Operates fine, but I am not sure how UAC would effect it.

Preserve mapped drive letter information during UAC elevation

We have an application that needs to know the path that it is executed from (which is always a network path).
We set up part of our configuration based on the path that the application is launched from, and we really want that configuration to use mapped network drive paths instead of the UNC path to the resource.
What we've found is that when we launch our application without UAC elevation, we are able to get the directory that the application launched from using
GetModuleFileName(NULL, buf, sizeof(buf));
But when we launch elevated (which we actually need to do), the buffer returned gives us a UNC based path instead of a drive letter based path.
Note that we always launch from Windows Explorer by navigating into the folder tree of the mapped drive letter.
Does anyone have any suggestions on how to get the drive letter based path of the EXE from a process that is running elevated?
Mapped Network Drives with UAC

Resources