Start VPN from SSIS package? - windows

Using SSIS I need to retrieve data from a server outside my network/domain.
I can only get to this server through a VPN.
I created 2 packages:
StartVPN - using some VB this package starts the VPN. Works great. :)
Import Files - This package is called from StartVPN and should import some data.
When I run package 2 directly with the VPN already started this package runs great.
When I run package 2 from package 1 without the task that starts the VPN but with the VPN manually started this package runs great.
However, if I call this package from package 1 it fails with the error:
The AcquireConnection method call to the connection manager "MyConnection" failed with error code 0xC0202009.
It does not matter if the VPN was already started or not.
How can I runn package 2 with the VPN only running during execution of the package?

I solved it!
I needed to add a wait between package1 (starting the VPN) and package2 (doing the import)
After setting up the VPN, package1 was made to wait 5 secs before continuing. Now everything works swell :)
SO: Package 1 containg a VB scriptask for starting up the (existing) VPN:
Dim VPNConnectionName As String = "MyVPN"
Dim VPNlogin As String = "MyUser"
Dim VPNPassword As String = "MyPass"
Shell("RASDIAL " & Chr(34) & VPNConnectionName & Chr(34) & " " & VPNlogin & " " & VPNPassword, vbNormalFocus)
'
System.Threading.Thread.Sleep(5000)
Dts.TaskResult = ScriptResults.Success
Then from package1 call package 2 for the actual import
And a VB scripttask for closing the VPN:
Dim VPNConnectionName As String = "MyConnection"
Shell("RASDIAL " & Chr(34) & VPNConnectionName & Chr(34) & " /DISCONNECT", vbNormalFocus)
'
Dts.TaskResult = ScriptResults.Success

Related

VBS script to scan and install all devices

I'm trying to figure out a way to scan all devices (without drivers installed) and install them one by one automatically.
I've made a simple script that adds/removes a registry value for driver locations, since we have a server with all the current drivers and it's updated frequently, so instead of pointing device manager to that location manually the script does it for me.
Problem is we work in a production environment and we have a lot of different devices to install, and doing it manually takes too long, even with the script i have to click each device and update the driver, the scripts just makes it a little easier by pointing it to the server with the drivers.
So basically i'm try to make the script add the location (this works fine ATM) and them update each device without prompting the user.
Option Explicit
Set ws = WScript.CreateObject("WScript.Shell")
Dim s, ws, rl
rl = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\"
s = InputBox("Please select what you want to do" & _
vbCrLf & vbTab & "1 - Clear all, set default driver path." & _
vbCrLf & vbTab & "2 - Default path + production drivers" & _
vbCrLf & vbTab & "3 - Default and production path + Skylake drivers")
If s = 1 then
ws.RegWrite rl & "DevicePath", "%SystemRoot%\inf" , "REG_EXPAND_SZ"
ElseIf s = 2 then
ws.RegWrite rl & "DevicePath", "%SystemRoot%\inf; B:\LocalDrivers\; \\ccdsrv01\shares\Resources\Drivers\Client" , "REG_EXPAND_SZ"
ElseIf s = 3 then
ws.RegWrite rl & "DevicePath", "%SystemRoot%\inf; B:\LocalDrivers\; \\ccdsrv01\shares\Resources\Drivers\Client; \\ccdsrv01\shares\Resources\PreProd\SkyBay (Skylake-SunrisePoint)\New" , "REG_EXPAND_SZ"
End If

Dependencies for VB6 connection to Oracle DB

I have an old VB6 app which uses ADO to connect to SQL server databases, as:
Dim cnServer As New ADODB.Connection
cnServer.Provider = "sqloledb"
sConnectString = "Server=" & txtServer.Text & ";" & _
"Database=" & txtDatabase.Text & ";" & _
"User ID=" & txtUserID.Text & ";" & _
"Password=" & txtPassword.Text & ";" & _
"Connect timeout=10"
cnServer.Open sConnectString
...which has always worked. But now I need to modify it to connect to an Oracle 11g database. I found this article and modified the code to:
Dim cnServer As New ADODB.Connection
cnVLServer.Provider = "OraOLEDB.Oracle"
sConnectString = "Server=" & txtServer.Text & ";" & _
"Data Source=" & txtDatabase.Text & ";" & _
"User ID=" & txtUserID.Text & ";" & _
"Password=" & txtPassword.Text & ";" & _
"Connect timeout=10"
cnVLServer.Open sConnectString
...but when I run it, I get an error that reads 3706, Provider cannot be found. It may not be properly installed. This happens on my development VM (which -- don't laugh -- is still on Win2K Pro), and also on my test machine (which uses Win XP).
Some further searching indicated that oracore11.dll is a dependency, so I went to Oracle's download site and pulled down this DLL as part of a .zip file containing what I take to be the full suite of Windows-related coding tools. However the error still occurs even if I place this DLL in the same folder with my VB6 executable. And when I try to register the DLL, the attempt just generates another error: The specified module could not be found.
Before any further thrashing with what may be a wrong path or an unsolvable problem in the first place, I figured I should check in and see the best/easiest way to get a VB6 app to connect to Oracle in the first place. My goal here is to have this VB6 app be as portable as possible, not requiring any pre-installed packages to work, and having the minimum set of dependencies be easily passed around with the .exe itself. (For reference, this VB6 app is not a commercially-distributed product, just an internally-used testing tool within my own department at work. It takes flat-file fixed width data, parses it, then generates the SQL code to insert it to the DB.)
To configure an Oracle Database Instant, you must:
Install the Oracle Database Instant Client and its ODBC driver on your system;
Set the TNS_ADMIN environment variable;
Configure a tnsnames.ora configuration file for your client.
Please refer to this link, for further details...

Running a vbs file via a scheduled task on Server 2003

I've been working on modifying an existing vbscript. The wierd part is that when I run the script manually, it works fine. But as soon as I try to run it as a scheduled task, it reports as complete, but doesn't actually do anything. After much troubleshooting, I think I tracked it down to the original CreateObject. Here's the code:
On Error Resume Next
'create an instance of IE
Dim oIE, objFSO, linenum
linenum = 0
Set oIE = CreateObject("InternetExplorer.Application")
'If err.number <> 0 Then linenum = 6
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForAppending = 8
Set objTextFile = objFSO.OpenTextFile ("C:\test.txt", ForAppending, True)
'objTextFile.WriteLine(now() & " Internet object created.")
'Execute our URL
'oIE.navigate("<intranet site>")
'objTextFile.WriteLine(now() & " Starting import")
'wait for the window to be closed (exit IE)
'Do Until Err : oIE.visible = True : wsh.sleep 1000 : Loop
'objTextFile.WriteLine(now() & " Import complete.")
if Err.Number <> 0 then
' An exception occurred
objTextFile.WriteLine("Exception:" & vbCrLf & " linenum: " & linenum & vbCrLf & " Error number: " & Err.Number & vbCrLf & " Error source: " & Err.source & vbCrLf & " Error description: " & Err.Description & vbCrLf)
End If
'clean up
'oIE.Quit
'oIE.Visible = False
'Set oIE = Nothing
I've commented most of it out, to narrow it down, and from the logging I added, it spits out the current error:
Exception:
linenum: 0
Error number: -2147467259
Error source:
Error description:
Yes, the source and description lines are blank.
Googling the error doesn't seem to bring up anything useful. So I'm not sure what's going on. Permissions have been checked multiple times, and it's always run as Administrator, the same user as I'm logged in as. The funny part is, this script works fine with Windows 2000. About the only thing I can think of is perhaps the Remote Desktop connection I'm using is somehow interfering with it.
Anyone have any ideas or things I might be able to try to resolve this?
For reference, when you've got problems googling a decimal error number, try converting it to hexadecimal. -2147467259 is the same as 80004005 and if you search for that you'll find that it's quite a common error and usually means that you're denied access to something so even if you're sure that it's not permissions for the things you've checked, it might be worth doing the following checks:
Does the scheduled task run under the same account as you used when you executed the script manually? Otherwise, try doing a RunAs on the script to run as the same user account as the task, if that works, try scheduling the task as your account.
That way you'll know if it's (task vs manual) or if it's (user1 vs user2). Which might make it a little easier to track down the issue.

How to set Authentication Methods in IIS programmatically

We are working on automating the deployment of some IIS applications. I've used cscript.exe inside a windows batch file to create the web app and such. There are however a few settings currently done by hand that I need to automate. Namely, if you look at the properties of an app, under Directory Structure -> Authentication and access control -> Edit, I need to uncheck Enable anonymous access and check Integrated Windows authentication.
Is there an easy way to do this from a windows batch file?
EDIT: I should clarify this is IIS 6.0, so appcmd is not available.
hope this helpes:
http://forums.iis.net/t/1159665.aspx
I answered a very similar question a wee while back. The example uses the asdutil.vbs tool which you can call from your batch file:
Setting NTAuthenticationProviders at an Application level in IIS 6 (Stack Overflow)
Updated:
Because you've already got a CScript script to create the website, you can just set the AuthFlags in the script:
'' Some values just as an example
iisNumber = 668
ipAddress = "172.16.3.200"
hostName = "myserver.com"
wwwfolder = "c:\mysites\www"
Dim serverBindings(1)
serverBindings(0) = ipAddress & ":80:www." & hostName
serverBindings(1) = ipAddress & ":80:" & hostName
'' Create server
Set w3svc = GetObject("IIS://localhost/w3svc")
Set newWebServer = w3svc.Create("IIsWebServer", iisNumber)
newWebServer.ServerBindings = serverBindings
newWebServer.ServerComment = "Server is: " & hostName
newWebServer.SetInfo
'' Create /root app
Set rootApp = newWebServer.Create("IIsWebVirtualDir", "ROOT")
rootApp.Path = wwwFolder
rootApp.AccessRead = true
rootApp.AccessScript = true
rootApp.AppCreate(True)
rootApp.AuthFlags = 4 '' <== Set AuthFlags here
rootApp.SetInfo
See Configure Windows Authentication (IIS 7):
appcmd set config /section:windowsAuthentication /enabled:true | false
For IIS 6 probably WMI is the alternative:
Creating Sites and Virtual Directories, and Setting Properties Using WMI
IIsWebServiceSetting (WMI)
AuthFlags
Dim sSitePath = "1" 'Set the site ID here
Set oSite = GetObject("IIS://localhost/" & sSitePath & "/root")
Select Case oSite.AuthFlags
Case 1
Wscript.Echo "Anonymous"
Case 2
Wscript.Echo "Basic"
Case 4
Wscript.Echo "NTLM"
Case 6
Wscript.Echo "MD5"
Case 64
Wscript.Echo "Passport"
End Select

How can I detect a Windows service at project build

I'm working on a solution that contains a Windows Service and a WinForms client that interacts with that service.
In my pre-build and post-build events, I have some net start and net stop commands to start and stop the service, but there are times when this causes a problem (file's not found, service is already stopped, etc.).
Is there a way to test if a service is running or installed prior to issuing net start?
I'd like to put this test in .cmd file and run it in the pre-build event for the project.
You actually don't need to install, start and stop service every time. Instead, consider adding a command-line key to your service executable so that when it's specified, is runs as a service (that is, performs usual ServiceBase.Run() stuff), and when this key is absent it runs as a regular console application. You'll get an added benefit of being able to dump logger output directly to the console so that debugging will be a whole lot easier.
if(args.GetLength(0) == 1 && args[0].ToUpper() == "/SERVICE")
{
ServiceBase[] services = new ServiceBase[] { new MyService() };
ServiceBase.Run(services);
} // if
else
{
InitAndStartWhateverIsNecessaryToRunServer();
Console.ReadLine();
} // else
Stick this into a vb script file and add to the pre and post build events.
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("SELECT * FROM Win32_Service WHERE Name = 'someService'")
Set objService = colRunningServices(0)
If objService.State <> "Running" And objService.State <> "Starting" Then
objService.StartService()
End If

Resources