Mapping a network drive only when connected to a Domain - batch-file

I have looked around a bit, and I haven't found a solution that exactly fits my needs. I have a Laptop that I use for work, and for personal use at home. At work, we are operating on a Domain, and have several Network Storage locations that I use often. So i decided that I want to Map these drives. However, I do not want to get popup messages nor see that these drives are disconnected when I am at home, and there is no connection to these servers. Is there a built in way to accomplish this task in windows 7, or am I going to need to resort to a start up script. If I need a script, how can I check to see if the computer is connected to a Domain, and then map drives based on that option. If a script is required, I would prefer to use a .bat file. Another route that would be achievable is doing this through group policy if someone can direct me as to how to push certain mapped drives to specific users.

Without more details, I believe if value of the Windows variable USERDOMAIN is equal to the value of COMPUTERNAME then your host is not in a domain
If %USERDOMAIN% <> %COMPUTERNAME% SET indomain="y"
Alternatively, you can 'hack' it by trying to do something like a DIR of a folder like WINDOWS on a computer that's part of the domain. If you get denied then you're not part of the domain.

Related

Way to Refresh Network Drives due to Disconnection from Pending VPN Connection without Workflow Interruption

Most of my company is currently working from home and is having to tunnel into our office network through a VPN. As such, all our network drives are, technically, disconnected until we login to the VPN. Once connected, we could simply open a file explorer window and open each network drive to reestablish/refresh the connection in Windows' eyes, but more than 2 or 3 drives is a hassle, and some of our members don't even think to do this every day even for our main project drive (only universal drive letter we use in our office) before opening some of our programs that need a network drive mapped, and thus have the potential to mess up our files or link therein.
Desired Solution:
I'm looking for a batch or cmd file that can run to refresh or reconnect the drives, without explicitly using NET USE if possible (more on why further down) or opening a file explorer by using a batch file to open a shortcut to a network folder. If this just isn't possible, I'll stick with the solution I have that uses NET USE, but would appreciate help smoothing out the issues outlined below.
I have a couple solutions that are more than a little intrusive in that they require some form of interaction to dismiss them once launched, rather than running, reaching eof, then closing using TIMEOUT /T 5. I was hoping there might be something a little more streamlined, or at least less intrusive, that I could use to avoid these unnecessary interactions that I'm currently dealing with:
Shortcut to a folder on each drive to "ping" said drive for refresh, but this opens a file explorer window, potentially interrupting workflow. I would like to suppress this window opening if possible, or at least immediately close it (not exactly how file explorer works, I know).
Batch file that tests all mapped drives for disconnected ones, then attempts to reconnect, sometimes causing a user input in the cmd window to interrupt workflow (We have two security levels each with their own login credentials, and several of us have mapped network drives using each of the two creds, so some disconnected drives will require manual entry of username and password when the /USER:%username% %password% parameters don't work, which I just can't seem to avoid. Neither server nor network location for NET USE are viable tests for which security level, as their labeled after the project itself rather than the security level needed, and so my only remedy here would be to suppress the asking for user input).
Multiple batch files, one for each drive, requiring users to manually copy and alter batch files for their own needs (only one drive is universally used for each project we're on, and even then some people are one different projects), then updating the task scheduler to run each of their created files (not at all desirable, and as far as I'm concerned, unacceptable). If nothing else can be modified or work without interference, I can just using this to run on our company's default project drive letter, and let people worry about reconnecting the others as needed.
I have a task scheduled for any time our VPN client reports a connection, which due to our home networks and/or the connection between us and the VPN servers, could occur multiple times a day (I've had up to 4 or 5 "connection" events trigger my task after the initial login, though I only have to explicitly login the one time), which can cause further interruptions in workflow beyond just the initial VPN login run. I'm willing to accept any solution that uses NET USE as long as I can suppress the request for user input if the Windows login password doesn't work, or a shortcut if I can prevent the opening of a file explorer window. Alternative solutions are preferred, but I understand that may not be possible.
I have tested using DIR //server/foo, but it timed out for the same reasons that file explorer doesn't display the network drive as "connected" after VPN login is successful.
I've also had mixed results with setting the task scheduler to run my program off of a network connection as opposed to the "connect" event from our VPN client, mostly in that it didn't run reliably, if at all, as I needed to wait until I was connected through the VPN, not just standard internet connection through an ethernet cable. For this, I tried using both methods here, but none of the networks that are available after VPN login seemed to trigger the task properly, even though manually triggering the even through Task Scheduler showed the action would run fine. As such, I'm considering this as a failure, but can revisit if no more streamlined solutions are available or I can get a guarantee this method won't trigger as often (preferably only once per login) as watching the VPN client for its connection event.
At this point, I'm stuck with two solutions that have a high potential to interrupt workflow and annoy the user too greatly for me to want to send out as a final solution (a for loop on NET USE where drive is disconnected and a batch file to open a shortcut that opens a window front and center), and another solution that I consider to limited in scope and as a last resort. I'll make due if there's not a better way to handle either of the first two, but in the mean time, I would greatly appreciate any help/advice!
Edit:
On a side note, I do expect to have the cmd window pop-up briefly, then close automatically once the operations are done (like it would with the shortcut solution), so some amount of workflow interruption will likely be unavoidable. What I'm considering unacceptable is that I can't minimize it and prevent the user form having to interact with it directly or indirectly to get the cmd or resulting window to close after it takes the active window status from whatever program user was previously in.
Edit 2:
I've posted this query elsewhere with this additional recap to help narrow my request:
As a recap, I'm looking for a solution for refreshing network drive connections that do no rely on Credential Manager, will not require user input if network drive credentials differ from windows login credentials, and will not pop-up a window that requires user to close manually. Brief workflow interruptions resulting from cmd or child-process windows popping up before closing automatically are acceptable, with a preference towards one of the two solution avenues I already have running. Thanks again for any input you may have!
I had the same problem. I have 4 mapped drives to reconnect to when I open the VPN and it was a real pain. I have looked for batch file solutions in vain.
My solution is to use a free program called FBackup. I use it anyway for the intended purpose of backing things up, but I noticed that when it opens, it reconnects all of my drives (including the mapped drives using the VPN to the office)
So after I connect, I open FBACKUP. It makes all of the connections for me, then I just shut it down. Job done.
1 this probably belongs on the site that this site was made to head up against, which I am unsure if I am allowed to reference by name on this site.
That said if it was at this site you probably want topost on Superuser.
That said..
For users with more than one drive mapping you want to store thier credentials used in windows credential manager so that the drives can automatically be mapped without specifying a username and password each time.
That will allow your batch script to run in the background and re-map the drives
In lack of a better answer that is viable for our setup (will definitely remember Ben's answer for later, in case I'm able to use it for the lower security profiles), I've decided to go with a more limited scope for my batch file, since I have yet to find any info that will allow me to suppress a file explorer window or request for user input from the cmd window (for password) when attempting to refresh connection to all saved network drives.
Since the one drive that absolutely must be reconnected is, by our guidelines, universally assigned to the same letter (mapping changes depending on the primary project we're on), I've opted for just refreshing this drive as the credentials for this drive will always match the Windows login credentials, and thus won't request user for input if a password is wrong.
I will keep tabs on this question, so that if someone else comes along and has a better solution, I will definitely swap the selected answer to them.

How are files on network mapped drives handled locally by a windows host?

This is by no means a "give me the solution" question, but more to gain a higher understanding. Please feel free to point to references where I can learn more about this, I've tried searching and all I get are how to's for setting up and accessing network drives.
I want to be able to monitor a file on a windows machine, but the file sits on a shared drive hosted locally. If it is manipulated by another machine, is there a process I can look for that will indicate that the file may be accessed by a resource elsewhere on the network? I understand that the host machine must be available in order to access the file in the first place, but what processes are called to actually manipulate the file. Is this below the OS level? I have access to a minifilter driver that I can ask a more experienced developer on the team to help me with if need be.

How to transfer a file from Windows XP to a virtual machine inside vSphere 5.5?

I have a file on my desktop that I need to put onto one of the virtual machines, however when I search for solutions on how to do this many say to download third party software to do it, or to use drag and drop through vSphere. The issue is I am on a restricted network and can't install additional software, and also don't have the drag an drop functionality in vSphere.
I have seen it done in the past using the command line and the IP address of the machine I want to send it to, along with the username and password, however I can't remember the syntax. Can anyone provide instruction on what to type into the terminal to do this?
Have you given the Copy-VMGuestFile cmdlet a look from PowerCLI?
http://www.vmware.com/support/developer/PowerCLI/PowerCLI651/html/Copy-VMGuestFile.html
If you're not a fan of PowerShell, there's a couple SDK options you could use with the vSphere Web Services API. Specifically, you're looking for the GuestFileManager object and the InitiateFileTransferToGuest method: http://pubs.vmware.com/vsphere-5-5/topic/com.vmware.wssdk.apiref.doc/vim.vm.guest.FileManager.html

Remote Desktop Application - Start multiple sessions on my client PC

I have a windows 2016 server running RDS. It is configured to run a single application when a user accesses it from a .rdp shortcut. The user just sees the application as though it is running on their local machine, not a whole remote desktop.
If from a client PC, if I launch the application and log in then I can see a new connection in the RD Gateway manager.
However if I launch the application from the same client PC multiple times I am only asked to login the first time, and whilst I see many instances of the application I only see one connection in the RD gateway manager.
I would like a new connection each time I launch the application, so that I can simulate multiple users running the app concurrently in their own sessions.
I have tried adding "prompt for credentials on client:i:1" to the .rdp shortcut and this has no effect.
Thanks you your help.
I don't think it's possible. Let me try to explain:
Whenever you launch the RDP file, you connect to a session on the RDSH. Now, if you want separate connections, that means that there should be multiple sessions (probably for the same user since the credentials don't change) which is not allowed by the RDSH by default.
Assuming you get passed multiple sessions for same user, MSTSC actually recognizes that for the given RDP file, there is already an open connection, so it will try to reuse that.
Last but not least, there is the problem of licensing - you are "working around" the system: both per-device and per-user licensing would report 1, therefore it would probably be a violation of ToS.
It would be much more useful if you could tell us what you are trying to achieve and then maybe we can help you more.
P.S.: This question has nothing to do with programming, so it probably belongs to https://superuser.com
Hi I figured out a solution to this, so I will share in case it is useful for anyone else.
Modify the hosts file to include different names for the target machine ip address:
eg:
51.xxx.159.233 test1.xxx.uk-user1
51.xxx.159.233 test1.xxx.uk-user2
51.xxx.159.233 test1.xxx.uk-user3
51.xxx.159.233 test1.xxx.uk-user4
Then in each rdp launch shortcut, reference a different alias.
eg:
Shortcut1:
full address:s:test1.xxx.uk-user4
Shortcut2:
full address:s:test1.xxx.uk-user3
Then when the RDP is launched it will ask you to log in even if you already have an active connection and server will have a new user logged into it.
Hope this helps somone in the future.

Is it possible to change the IP address and Device Name in Windows CE via CMD or Batch?

Ideally, I'd have a batch file on my desktop that I could click to quickly change these configurations, but the batch scripting tutorials I've been looking at don't seem to work for Windows CE. Anyone know how to do this?
I want to set a static IP, Subnet Mask, Default Gateway, and Device Name.
If you want an easy and fast way (as double clicking a bat) to change your network configuration, typically you'll need to write a tool.
The tool must:
change values in the registry for your network adapter; the registry entries are something like:
[HKEY_LOCAL_MACHINE\Comm\NETADAPTER\Parms\TcpIp]
"IpAddress"="192.168.0.100"
"DefaultGateway"="192.168.0.1"
"Subnetmask"="255.255.255.0"
ask the adapter to renew his address (you can use NDISConfig.exe to do this)
If you have an hive based registry (data in registry are stored permanently and will be there after a reboot) you can reboot the device to easily implement the second step.
Hope this is helpful

Resources