Thanks for the insight. I think I will do as you say and stick with the if statement rather than set it if there is an exception call when trying to invoke slmgr.vbs with the .Start() method...
its all good really i just stated how i would do it and i really hope it helped you in anyway. im still learning vb.net thats why my code is somewhat random but it always seems to work out
They will both work if implemented correctly, and both will decide in real-time whether or not to use slmgr to install the product key & certificate... I like it because the user has to click or select nothing, the tool does it all for them. If there is no slmgr present then it will not be used.
in my tool i did it to give the user more options really i didnt want to force something that didnt need to be forced
thats true but what if the user would like to install the key with the way he/she knows how to do it anyways wmi might fail if sppsvc is off
Well, if user has no slmgr and sppsvc is off then I guess they may be out of luck... I would recommend a Win7 reinstall at that point, then use the l0ader
slmgr.vbs uses wmi to do its job, at one point I copied and pasted the functions in to new scripts to see how they work slmgr -ipk Code: Key = "" strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") On Error Resume Next Set colServices = objWMIService.ExecQuery("SELECT Version FROM SoftwareLicensingService") QuitIfError() For each objService in colServices QuitIfError() Exit For Next objService.InstallProductKey(Key) objService.RefreshLicenseStatus() Wscript.Quit slmgr -ilc Code: cert = "cert.xrm-ms" LicenceData = ReadAllTextFile(cert) strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Dim objService Dim colServices On Error Resume Next Set colServices = objWMIService.ExecQuery("SELECT Version FROM SoftwareLicensingService") QuitIfError() For each objService in colServices QuitIfError() Exit For Next set GetServiceObject = objService objService.InstallLicense(LicenceData) objService.RefreshLicenseStatus() Wscript.Quit '================================================== 'function ReadAllTextFile '================================================== Function ReadAllTextFile(strFileName) Dim strData Dim oStream Set oStream = CreateObject("ADODB.Stream") oStream.Type = 2 'adTypeText oStream.Open oStream.Charset = GetFileEncoding(strFileName) oStream.LoadFromFile(strFileName) strData = oStream.ReadText(-1) 'adReadAll oStream.Close ReadAllTextFile = strData End Function '================================================== 'function GetFileEncoding '================================================== Function GetFileEncoding(strFileName) Dim strData Dim strEncoding Dim oStream Set oStream = CreateObject("ADODB.Stream") oStream.Type = 1 'adTypeBinary oStream.Open oStream.LoadFromFile(strFileName) ' Default encoding is ascii strEncoding = "ascii" strData = BinaryToString(oStream.Read(2)) ' Check for little endian (x86) unicode preamble If (Len(strData) = 2) and strData = (Chr(255) + Chr(254)) Then strEncoding = "unicode" Else oStream.Position = 0 strData = BinaryToString(oStream.Read(3)) ' Check for utf-8 preamble If (Len(strData) >= 3) and strData = (Chr(239) + Chr(187) + Chr(191)) Then strEncoding = "utf-8" End If End If oStream.Close GetFileEncoding = strEncoding End Function '================================================== 'Function BinaryToString '================================================== Function BinaryToString(dataBinary) Dim i Dim str For i = 1 To LenB(dataBinary) str = str & Chr(AscB(MidB(dataBinary, i, 1))) Next BinaryToString = str End Function ' Returns string containing the whole text file data. ' Supports ascii, unicode (little-endian) and utf-8 encoding. Function ReadAllTextFile(strFileName) Dim strData Dim oStream Set oStream = CreateObject("ADODB.Stream") oStream.Type = 2 'adTypeText oStream.Open oStream.Charset = GetFileEncoding(strFileName) oStream.LoadFromFile(strFileName) strData = oStream.ReadText(-1) 'adReadAll oStream.Close ReadAllTextFile = strData End Function
I just posted O7A v1.1.1, then I saw your comment... I am trying to decide if I should implement code to check if slmgr is missing and sppsvc is not running, then attempt to start sppsvc via cmd.exe... But then what if cmd.exe is missing too...man, it is a never-ending ordeal I think I will leave it as I have it for now, and if there are many issues with people not having slmgr nor sppsvc running, then I will add additional code...lol.
I think it will be fine for now...I mean, if the user uses O7A 1.1.1 and cannot act!vate, then they have serious problems with their Windows 7... Like slmgr.vbs and cmd.exe must be gone and sppsvc must be stopped all together to stop O7A from installing (I think anyway if I have implemented everything correctly)... I think if O7A fails then the user may want to consider reinstalling Windows 7, because they have some serious issues.
Well, I hope people let me know if they have any issues...and if so, try to hit print screen and get a picture of the problem if there is one. Thanks for everyone's help/input/suggestions. I cant fall asleep again now so I think I am gonna bust out some modern warfare 2...! I actually killed my xbox 360 DVD drive last night playing it for like 8 hours straight (the drive had been making noises for a while and it finally died last night (disk read errors), so I had to stay up for another 45 minutes to an hour or so removing the old DVD drive (it was a bitch to cr@ck the case open), then flashing the old firmware onto the new drive, then installing the new drive...so I am good to go again today. )