Tuesday, December 22, 2015
Map Windows Share to a Drive Letter using batch file / command line and prompt for password
@ECHO OFF
rem net use /del V:
SET /P %password%=Password:
net use v: \\Wtjwh175\c$\dev\dropbox /u:"yourDomain\yourUsername" %password%
Technically, you will get an error saying "The local device is already in use.", if you run it twice. If you don't want that to happen you can uncomment line 2 (change rem net use /del V: to net use /del V:). This will unmap the drive and then map it again each time the batch file is executed.
Wednesday, June 15, 2011
Using Batch File or Command Line to recursively find all files that have a filename that contains a particular string
It sounds like a tall order at first, but then it also sounds like something that should be built into Windows. In particular, I am using Windows 7, but I assume it works on XP as well.
The solution is actually quite simple and is indeed built into Windows 7.
dir /s /b *my string*
This will give you something similar to:
c:\temp\This is a test of my string.txt
c:\mydocs\My string could be found here.txt
As shown above it will search the current directory and all directories below the current one for files that contain ‘my string’. You can also specify something like this to specify the directory you want to start searching in regardless of your current directory.
dir /s /b “c:\mydocs\*my string*”
You can use all the standard wild card syntax such as the following to search only .html files.
dir /s /b “c:\mydocs\*my string*.html”
In case you are wondering the /s is for recursive and the /b is to return just the path\filename (no file info such as date, size, etc).
Tuesday, April 12, 2011
How to determine if your Windows 7 Firewall is blocking your connection
If you are like me, you cannot turn off your Windows 7 Firewall for even a minute on your work computer. If you are lucky enough to have admin rights on your computer or you can add a rule to your firewall then you are in luck. It just so happens that you can add a rule that allows most anything to open a connection from your laptop to just about anywhere.
To add a rule, go to the Start Menu | Administrative Tools | Windows Firewall with Advanced Security. Right-click the Inbound Rules on the left navigation area and then select New Rule…
Next choose Custom rule. Click the next button.
Leave all programs setting. Click the next button.
Leave Protocol type to Any. Click the next button.
Leave IP addresses as Any. Click the next button.
Make sure Allow the Connection radio button is check. Click the next button.
Choose all three (Domain, Private, Public). Click the next button.
Give the rule something descriptive.
You have now opened up your computer for potential attack (at least from inbound). I highly recommend you not keep this rule enabled.
Thursday, April 7, 2011
Can’t access SQL Server Cluster or non-standard port or named instance after upgrading to Windows 7
After I migrated to Windows 7 we were not able to connect to the SQL Cluster using MS SQL Management Studio, Linqpad,Visual Studio, my apps, odbc, etc. The reason is that Windows firewall blocks non-default ports for SQL Server.
Determine if the Windows Firewall is the cause
The first thing you probably want to do is confirm that it is actually a Firewall issue. The easiest way (if you are lucky) is to just turn off the Windows Firewall. If you are not lucky enough to be able to turn off your firewall due to corporate policies then there is still hope. To help troubleshoot this, I created a rule in the Firewall that opened up all ports for all programs. Click here to see the details of how to do this.
Once you have determined that the firewall is the issue, you may want to open the port instead of opening it for individual programs or open all ports between your computer and the server you are trying to access.
Option 1: Open Firewall for server
This seems to be the easiest by far since you only have to do it once unless you change server ip addresses or ports.
To add a rule, go to the Start Menu | Administrative Tools | Windows Firewall with Advanced Security. Right-click the Inbound Rules on the left navigation area and then select New Rule…
Next choose Custom rule. Click the next button.
Leave all programs setting. Click the next button.
Leave Protocol type to Any. Click the next button.
Leave local IP addresses as Any. Add ALL IP addresses that you server has to the list of remote IP Addresses. I was surprised that I needed all the ip addresses for the server (use ipconfig from the command line if you don’t know them) and not just one, so to be safe add them all. Click the next button.
Make sure Allow the Connection radio button is check. Click the next button.
Choose only Domain (you may need to add private if you run into issues with vpn, etc). Click the next button.
Give the rule something descriptive.
NOTE: A slightly more secure version of this would be to specify TCP as the Protocol instead of Any. Copy the rule and edit it such that you change TCP to UDP. Then you’ll have one rule for TCP and one for UDP. This is the method I personally chose.
NOTE: You could do the same, but do it for you subnet, but that is a bit riskier from a security standpoint, though not bad on a corporate network. Just be certain to select domain (no public or private).
Option 2: Open Firewall for each program
To fix the issue, go to your Start menu | Control Panel | Windows Firewall | Allow a program or feature through Windows Firewall | Change Settings | Allow another program…
Next choose your program such as MS SQL Management Studio, Linq pad, Visual Studio, odbc, etc. Be sure to click the Network location types… button and select Home Network if you connect from home (and have selected that connection to be a home connection). FYI, to create an odbc connection using a non-standard port you will need to add the C:\Windows\System32\odbcad32.exe program.
Side note on MS Access: If you are trying to have your MS Access application access a linked server that uses ODBC to connect to the SQL Server you will need to create a new ODBC Data Source, but be sure NOT to make it a System DSN. You want to select User DSN otherwise MS Access will not be able to access it. Though, I imagine if you ran MS Access as administrator you could make it work that way with a System DSN.
I still had trouble when running in Visual Studio 2010 when debugging (worked fine if just ran without debugging). I never did figure out how to get past this. If anyone knows, please let me know.
Option 3: Hardcode server ip address
Workaround, if you can’t change your Firewall, you need admin rights on your machine I think. If you can’t do that, then you can always access the server using the ip address and port number separated by a comma. I don’t know why it works, but it does (at least on my machine).
Legal like warning: I am by no means a security or firewall guru. Please don’t take these as security recommendations. I simply figured out how to solve the problem while taking the security issues into consideration the best way I know how (I’m a programmer not a security expert). So, please don’t make these changes unless you understand the risks as you are messing with firewall rules that are meant to protect your computer from attack. You assume all responsibility for your changes.
Wednesday, April 6, 2011
Visual Studio 2010 won’t debug under Windows 7
I found out that Visual Studio 2010 won’t let the debugger started until I run Visual Studio 2010 with Run as Administrator. I think I figured out why. Here is an account of what I was seeing and how I fixed it.
I could open my C# ASP.NET web application just fine using Run (Control-F5). Then I tried to do it with Debug (F5) and I got the following message:
Unable to launch the ASP.NET Development Server.Uncaught exception thrown by method called through Reflection.
I then Googled that error message. I found this link. I go to the section 2.4.11.2 (shown below).
2.4.11.2 Debugger start fails if the IntelliTrace recordings directory is Read-Only
By default, IntelliTrace files are located in the "%ProgramData%\Microsoft Visual Studio\10.0\TraceDebugging\" directory. If this directory is made read-only, or the directory is changed to a read-only location, an uncaught exception gets raised to the user. "Error while trying to run project: Uncaught exception thrown by method called through Reflection."
To resolve this issue:
Option 1: Modify the permissions of the directory to be writable.
Option 2: Change the directory where IntelliTrace recordings are stored.
- ○ In Visual Studio, open the Options dialog box.
- ○ Expand the IntelliTrace item in the left pane of the dialog box.
- ○ Click the Advanced item under IntelliTrace.
- ○ Change the IntelliTrace recordings directory to one that is not read-only.
- ○ Click OK.
I tried both option 1 and Option 2. The problem is that when I tried Option 1 and went to the directory suggested, it was not there. When I tried Option 2 I got the following message where I was expecting to see some kind of useful UI:
An error occurred loading this property page.
Then I got the idea, what if Visual Studio 2010 needs to be run as administrator even though I am an admin under. I am knew to Windows 7, but I am quickly learning that most techie tasks require the programs to be Run As Administrator; Visual Studio is no exception to this. It seems that I am not the only one to come to this conclusion. Here Microsoft suggests changing Visual Studio 2010 to run as Administrator and I have shown instructions below:
If you are running Windows Vista, you must start Visual Studio by going to the Start menu and right clicking Visual Studio 2010 and selecting Run as Administrator. To always launch Visual Studio 2010 as an administrator you can create a short cut, right click the short cut, select properties, select the Compatibility tab, and check the Run this program as an administrator checkbox. When you start Visual Studio 2010 with this shortcut, it will always run as administrator.
The good news is that after to run VS2010 (Visual Studio 2010) as Administrator the proper directory structure will be created and the if you happen to run VS2010 without running it as Administrator you can now run as Debug (F5) and you can also go to the Options | IntelliTrace | Advanced and see a useful UI with no errors.
I think to keep things simple I will run VS2010 as administrator at all times.