I tried to uninstall the windows application exe which is already installed in my system using VBScript. But was not able to Uninstall the exe. Please help me on this. Thanks in advance.
I tried with following code:
Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."
'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{XXXXC6BA-0F96-4E3B-BB14-211E2805XXXX}"
'********************************
' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")
'**************************
UninstallString = "Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
IF subkey = ProductCode Then
oShell.Run UninstallString, 1, True
End If
Next
Set oShell = Nothing
Set oReg = Nothing
MODIFIED CODE
Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."
'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{4AE9C6BA-0F96-4E3B-BB14-211E2805227E}"
'********************************
' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")
'**************************
UninstallString = """C:\Program Files\ASCO\DatabaseUpgradeUtility\ASCO Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
'UninstallString = "ASCO Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
InputBox(UninstallString)
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
'IF subkey = ProductCode Then
'.Run UninstallString, 1, True
'End If
IF subkey = ProductCode Then
oShell.Run "%COMSPEC% /k " & UninstallString, 1, True
End If
Next
Set oShell = Nothing
Set oReg = Nothing
tried the above and the path also trid with out double quotes also but both are not working. Please provide me if any thing that i have to change in the above script.
Your executable name has spaces in it, so you need to put double quotes around it, otherwise the shell object will try to run an executable Database, which cannot be found.
Change this line:
UninstallString = "Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
into this:
UninstallString = """Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
Also, make sure that the path to Database Upgrade Utility.exe is in the PATH environment variable. If it isn't, you need to run the executable with its full path.
UninstallString = """C:\Program Files\ASCO\DatabaseUpgradeUtility\ASCO Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
If that doesn't work, check the following things:
Is the Run statement executed in the first place? Change the conditional like this to see if the code actually goes into the Then branch:
IF subkey = ProductCode Then
WScript.Echo "Subkey check OK."
oShell.Run UninstallString, 1, True
End If
Does the uninstall command return an error code?
IF subkey = ProductCode Then
rc = oShell.Run(UninstallString, 1, True)
If rc <> 0 Then WScript.Echo "Command returned with status code " & rc & "."
End If
Does the uninstall command produce output on the console?
IF subkey = ProductCode Then
oShell.Run "%COMSPEC% /k " & UninstallString, 1, True
End If
Related
I'm trying to convert the Bodies from Parts to Parts in a Product in CATIA. I found a VBA script that works fine, but I have to translate it to C#.
The VBA script is the following:
Sub GreateProductsFromBodies_SelectAllBodies()
On Error Resume Next
Set CATIA = GetObject(, "CATIA.Application")
'Declare variables
Dim oPartDoc As PartDocument
Dim oPart As Part
Dim oProductDoc As ProductDocument
Dim oProduct As Product
'Create a new ProductDoc and rename it's PartNumber equals to Partdoc's PartNumber
Set oPartDoc = CATIA.ActiveDocument
Set oProductDoc = CATIA.Documents.Add("Product")
oProductDoc.Product.PartNumber = oPartDoc.Product.PartNumber
'Arrange windows use "Title Vertically" ,then active window contain Partdoc
CATIA.Windows.Arrange catArrangeTiledVertical
CATIA.Windows.Item(1).Activate
'Check the Body's name use "For ... Next"loop . If Body's name duplicate,then rename.
Dim j As Integer, k As Integer
For j = 1 To oPartDoc.Part.Bodies.Count
For k = 1 To oPartDoc.Part.Bodies.Count
If oPartDoc.Part.Bodies.Item(j).name = oPartDoc.Part.Bodies.Item(k).name And j <> k Then
oPartDoc.Part.Bodies.Item(j).name = oPartDoc.Part.Bodies.Item(k).name & "_Rename_" & j
End If
Next
Next
'Copy Bodies from PartDocument
Dim i As Integer, ProductPN As String, FinalProductPN As String
For i = 1 To oPartDoc.Part.Bodies.Count
With oPartDoc.Selection
.Clear
.Add oPartDoc.Part.Bodies.Item(i)
.Copy
.Clear
End With
'Modify the Product's PartNumber,replace "\" and "."to "_" ,then delete Space
ProductPN = oPartDoc.Part.Bodies.Item(i).name
If Right(ProductPN, 1) = "\" Then
ProductPN = Left(ProductPN, Len(ProductPN) - 1)
End If
FinalProductPN = Replace(Replace(Replace(ProductPN, "\", "_"), ".", "_"), " ", "") 'Replace "\" and "."to "_",Delete Space
'Paste Body in Product's Part as Result
Set oProduct = oProductDoc.Product.Products.AddNewComponent("Part", FinalProductPN) 'Add Part
With oProductDoc.Selection
.Clear
.Add oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent.Part
.PasteSpecial "CATPrtResultWithOutLink"
.Clear
End With
oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent.Part.Update
Next
'Use Msgbox to echo the complete flag
MsgBox "All the select Bodies had been created as a PartDocument successfully !" & Chr(13) & _
">>> The Partdocument's Bodies's count : " & oPartDoc.Part.Bodies.Count & Chr(13) & _
">>> The ProductDocument's PartDocument's count : " & oProductDoc.Product.Products.Count, _
vbOKOnly + vbInformation, "#LSY >>> CATIAVBAMacro of Part to Product >>> Run Result"
End Sub
I translated every line, except the line:
oProductDoc.Selection.Add oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent.Part
I found no corresponding property in C#, cause the last property Part is missing in C#.
I wrote:
oProductDoc.Selection.Add(oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent.??????);
I'm very thankfull for every help!
I solved it, if someone else is in this situation:
I had to cast the line as PartDocument, whish gives me the needed .Part Property!
Before the selection:
PartDocument partDoc = oProductDoc.Product.Products.Item(i).ReferenceProduct.Parent as PartDocument;
And in the required line:
oProductDoc.Selection.Add(partDoc.Part);
I need to increment version of an installer on every successful build. I have added a VBscript file and called it from a pre-build event. But am not able to get the actual result. my script is as under:
set a = wscript.arguments
if a.count = 0 then wscript.quit 1
'read and backup project file
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(a(0))
s = f.ReadAll
f.Close
fbak = a(0) & ".bak"
if fso.fileexists(fbak) then fso.deletefile fbak
fso.movefile a(0), fbak
'find, increment and replace version number
set re = new regexp
re.global = true
re.pattern = "(""ProductVersion"" = ""8:)(\d+(\.\d+)+)"""
set m = re.execute(s)
v = m(0).submatches(1)
v1 = split(v, ".")
v1(ubound(v1)) = v1(ubound(v1)) + 1
vnew = join(v1, ".")
'msgbox v & " --> " & vnew
s = re.replace(s, "$1" & vnew & """")
'replace ProductCode
re.pattern = "(""ProductCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
s = re.replace(s, "$1" & guid & """")
'replace PackageCode
re.pattern = "(""PackageCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
s = re.replace(s, "$1" & guid & """")
'write project file
fnew = a(0)
set f = fso.CreateTextfile(fnew, true)
f.write(s)
f.close
and my Pre-build Event is as C:\Projects\VersionProject\myscript.vbs "$(ProjectDir)VersionProject.Installer.vdproj" .Any help appreciated.
You'd need to go into the vdproj file and find the string of the form "ProductVersion" = "8:1.0.0"
and change the string from (say) 1.0.0 to 1.0.1.
However you're likely to get into trouble with updates if that's all you change. Note that when you increment the ProductVersion in the setup project it prompts to change ProductCode, and it will also change the PackageCode of the MSI file. So a safe change of the version involves all those things. For example, if you change only the version and attempt to reinstall the MSI it will fail with "Another version of this product is already installed". If you're unaware of these things, I suggest you familiarise yourself with how ProductCode, UpgradeCode, ProductVersion all interact, together with RemovePreviousVersions, and be aware that every new MSI created needs a new PackageCode.
Take a look at this. This Plugin allows you to set various options for the version number in your project.
And it does exactly what you need, auto increment the version number on each build . I've been using this for years and never had problems with it.
Update:
This Plugin only works if your project has an AssemblyInfo.cs
Regarding the GetSetting() function in .NET, i have found the GetAllSettings(). That is, GetAllSettings("MyApp", "MySection") will give me all keys under "MySection". I can't, how ever, find anything for getting all sections for my App. In the case above, i would like to get "MySection" as an result for searching "MyApp".
Any ideas?
Try this (C#):
var regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\MyApp",
RegistryKeyPermissionCheck.ReadSubTree));
var sections = regKey.GetSubKeyNames();
I'm not sure about VB but you may have to use Registry.CurrentUser instead of LocalMachine and then modify the path accordingly (SOFTWARE\MyApp is the path here), based on where your keys are. More info here
Here's the corresponding code for VB.Net - taken from here
Dim rkTest As RegistryKey = Registry.CurrentUser.OpenSubKey("RegistryOpenSubKeyExample")
Console.WriteLine("There are {0} subkeys under Test9999.", _
rkTest.SubKeyCount.ToString())
For Each subKeyName As String In rkTest.GetSubKeyNames()
Dim tempKey As RegistryKey = _
rkTest.OpenSubKey(subKeyName)
Console.WriteLine(vbCrLf & "There are {0} values for " & _
"{1}.", tempKey.ValueCount.ToString(), tempKey.Name)
For Each valueName As String In tempKey.GetValueNames()
Console.WriteLine("{0,-8}: {1}", valueName, _
tempKey.GetValue(valueName).ToString())
Next
Next
This code should work, just make sure your path etc. is being set properly. Or if you can post a screenshot of your registry hives, I can guide you better.
Firs of, i am new here and hope you can help.
I am a systen engeneer and have to move (copy) 400 out of 500 folder's in a directory.
The folder names are uniek GUID {f199a57f-fbee-411b-a70e-32619f87e6aa} naming
Is there a VB or C# way to have the user input the 400 names of the folders that need to be copyd and let the scrip search them and copy the folders too a new location?
Thank you for your help...
Regards,
Wim
Wat i tried:
I tried this, but noting hapens :-(
Sub CopySomeFolder()
Dim FSO, sourceFolder, currentFile, filesInSourceFolder
Dim strSourceFolderPath
Dim strDestinationFolderPath
Dim strUserInput
Set FSO = CreateObject("Scripting.FileSystemObject")
' Figure out which folder to copy from where to where
strUserInput = InputBox("Please enter name of file to copy.")
strSourceFolderPath = "M:\"
strDestinationFolderPath = "M:\"
Set sourceFolder = FSO.GetFolder(strSourceFolderPath)
Set filesInSourceFolder = sourceFolder.Files
' Look at all folders in source folder. If name matches,
' copy to destination folder.
For Each currentFile In filesInSourceFolder
If currentFile.Name = strUserInput Then
currentFile.Copy (FSO.BuildPath(strDestinationFolderPath, _
currentFile.Name))
End If
Next
End Sub
Decide whether you need to copy folders or files
Don't be a sadist - asking a user to type 400 GUIDs into an InputBox!
Use dir to create the list of all 500 folder in a text file
Ask your asistent to delete the 100 not to be copied
Use a .bat or .vbs to copy the 400 remaining folders
This is simple to do. Example script that will read a text file and move them is as fallows;
Const ForReading = 1
Const list = "c:\list_of_folders.txt"
Const destination = "c:\temp\"
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim folders : Set folders = fso.OpenTextFile(list, ForReading)
Dim folder
Do Until folders.AtEndOfStream
folder_loc = folders.ReadLine
If fso.FolderExists(folder_loc) Then
Set folder = fso.GetFolder(folder_loc)
folder.move(destination)
End If
Loop
Wscript.echo "Operation completed."
The list_of_folders.txt needs to have full paths.
First of, thank's for all your help...
We ended up using both answers. We got the DB admins to give us the GUIS's that have to be moved, slapt that in too 4 txt doc's, 1 for everyday of the migration. We used copy, not move for if something goes wrong.... here is the script i made...
Dim arrFileLines()
i = 0
set filesys = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserInput = InputBox ("Pathe to TXT file containing the folder names: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
strUserInputFrom = InputBox("Enter the directory path to the folders u want to copy: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
strUserInputTo = InputBox("Enter the destination folder: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"\\Servername\C$\Program Files)")
Set objFile = objFSO.OpenTextFile(strUserInput, 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close
For l = Ubound(arrFileLines) to LBound(arrFileLines) Step -1
Wscript.echo strUserInputFrom&"\"&arrFileLines(l) &" copy to " & strUserInputTo&"\"
filesys.CopyFolder strUserInputFrom&"\"&arrFileLines(l), strUserInputTo&"\"
Next
Please let me know if there is a better way, i like to learn :-)
Thanks
How do I export all of the names and email addresses from a distribution list in Outlook using code? I have access to an Outlook 2000 or Outlook 2007 client. Ideally I would like the code to be in C#.
I realize you asked about c#, but the following script from http://www.microsoft.com/technet/scriptcenter/resources/officetips/may05/tips0524.mspx may be of some use.
Const olFolderContacts = 10
Set objOutlook = CreateObject("Outlook.Application")
Set objNamespace = objOutlook.GetNamespace("MAPI")
Set colContacts = objNamespace.GetDefaultFolder(olFolderContacts).Items
intCount = colContacts.Count
For i = 1 To intCount
If TypeName(colContacts.Item(i)) = "DistListItem" Then
Set objDistList = colContacts.Item(i)
Wscript.Echo objDistList.DLName
For j = 1 To objDistList.MemberCount
Wscript.Echo objDistList.GetMember(j).Name & " -- " & _
objDistList.GetMember(j).Address
Next
Wscript.Echo
End If
Next
use outlook component model
http://www.dotnetjunkies.ddj.com/Tutorial/2E1EEEAF-C78A-4A38-A830-AC204B12DF83.dcik