Saturday, January 1, 2011

How to get the QBOE Cert Request (with code)

What a pain. To get a cert request from IE so that the private key stays in Windows.

Try this script (save as something.vbs) and run it on your server, logged in as the IDNRequestD login.

set Enroll = createobject("CEnroll.CEnroll")
Dim varName
' Enable error handling.
On Error Resume Next
' Attempt to use the control, in this case to retrieve a property.
varName = Enroll.MyStoreName
' If above line failed, Err.Number will not be 0.
if ( Err.Number <> 0 ) then
MsgBox("Error!")
Err.clear

else
' The control property was successfully retrieved,
' display the property value.
varName = "MyStoreName is " & varName
end if
Dim strDN
Dim strSvr
Dim strLogin
Dim strOrg
Dim strOU
Dim strCity
Dim strState
Dim strCountry
strSvr = "www.something.com"
strLogin = "something.something.com"
strOrg = "Someghing Inc"
strOU = "NA"
strCity = "Tyson"
strState = "New Mexico"
strCountry = "US"
strDN = "CN=" & strSvr & ":" & strLogin & ",OU=" & strOU & ",O=" & strOrg & ",L=" & strCity & ",S=" & strState & ",C=" & strCountry
Dim strReq
strReq = Enroll.CreatePKCS10(strDN, "1.3.6.1.4.1.311.2.1.21")
fstr = "-----BEGIN NEW CERTIFICATE REQUEST-----" & vbcrlf & strReq & "-----END NEW CERTIFICATE REQUEST-----"
StrFileName = "C:\Documents and Settings\IDNRequestD\reqFile.txt"
Set ObjFso = CreateObject("Scripting.FileSystemObject")

'Creating a file for writing data
Set ObjFile = ObjFso.CreateTextFile(StrFileName)

'Writing a string into the file
ObjFile.Write(fstr)


'Closing the file
ObjFile.Close

ProfileManager.LoadUserProfile fails

I needed to have a .NET component in Component Services run as another user, then call

ProfileManager.LoadUserProfile within the code.

It fails. I found this:

http://marianosz.blogspot.com/

Which pointed me in the right direction - the user has to be loaded first by the component, then it will work.

So, I right clicked on the component and said Start - the call now works.

But how to start a component without doing this manually?

So, I turned it into a windows service that starts up automatically (from the Component Services manager)

However, when I rebooted, it said Service did not start, logon failure. Had to go into services and reenter the password for the user.

Now it works.