Check existence of ini and edit
Hi all,
I am working on Citrix, Is there a way , I can check for the existence of ini files and if so, just edit the ini instead of overwrite it? Because There are few other apps when installed try to write to the same files.
Answers (7)
Sorry I had to enter a new answer. Looking at this script in the comments section is torture.
As far as adding content you can use the following. I've never tested this in a .ini and would be curious to see if it causes any issues. This will add the lines to the bottom of the file.
$output = "C:\path\to\file\your.ini" $ini = select-string $output -pattern "WFclient"
$ini2 = select-string $output -pattern "Program Neighborhood"
$text="
[WFClient]
ICASOCKSProtocolVersion=0
ICASOCKSProxyPortNumber=0
ICASOCKSTimeout=0"
$text2 = "
[Program Neighborhood]"
if ($ini -eq $null) {add-content $output "$text"}
else {continue}
if ($ini2 -eq $null) {add-content $output "$text2"}
else {exit}
Comments:
-
Excellent, thank you so much. Users machine does not recognise the powershell script. So client prefers a Batch or VBS..
Thanks again - shamu99 12 years ago -
What do you mean doesn't recognize? What OS is it? - dugullett 12 years ago
-
Oh.... Well that sucks. Well save this script for 2014. Then you'll have no other choice. - dugullett 12 years ago
-
lol , thanks for your help again - shamu99 12 years ago
If you are working with the K1K and kscripts, you would make a verify step to check for the file. If it is found, append the content in with something like >>. If it is not, in remediation copy the new file over.
If you are working entirely with a batch script, you can use IF EXIST [filepath] [command] to do something similar. IF NOT EXIST is also valid.
The ini basically contains
[Program Neighborhood]
CITRIX PROD=abcd99
Citrix QA=efgh99
[CITRIX PROD]
HttpBrowserAddress=
[WFClient]
ICASOCKSProtocolVersion=0
ICASOCKSProxyPortNumber=0
ICASOCKSTimeout=0
[Citrix QA]
HttpBrowserAddress=
Basically what I need to see is , the bold lettered lines are present even after the install of any other applications, say for example, after the empower installs on the machine, after citrix, it overwrites this ini file removing the program neighborhood and WFClient, after the reboot of the machine.
But I need a script that would check if this program neighborhood and WFclient are present in the ini file, if not , edit the ini and write those bold lines and along with the other lines.
If present then leave it as it is.
this should work even after a reboot, because empower will edit the ini after the reboot....
I think this is what you are looking for? If not let me know. In Powershell.
$ini = select-string C:\path\to\file\your.ini -pattern "[WFclient]" if ($ini -eq $null) {remove-item C:\path\to\file\your.ini} else {exit}
Comments:
-
Reading this again I'm thinking you want to overwrite so add this. Powershell can edit text, but it's a replace string as far as I know.
$ini = select-string C:\path\to\file\your.ini -pattern "[WFclient]"
if ($ini -eq $null)
{remove-item C:\path\to\file\your.ini
copy-item \\share01\share\your.ini c:\path\to\file\}
else
{exit} - dugullett 12 years ago -
Hi,
Thanks for the reply, Here the script is looking for the pattern WFClient , if not present it is removing the ini itself and copying a new ini from a share.
I want the script to check or read for the pattern "[programneighbourhood]" and '[WFClient]"
If is not present then write the same "[programneighbourhood]" and '[WFClient]"
in the same ini, without deleting the ini.
If "[programneighbourhood]" and '[WFClient]" are present then exit
if not paste "[programneighbourhood]" and '[WFClient]"
in the same ini. - shamu99 12 years ago
Hi all,
Is it possible for me to create the script with a batch or VBscript..
Any help is appreciated.
Comments:
-
Can you run this update? You need SP3.
http://www.microsoft.com/en-us/download/details.aspx?id=16818 - dugullett 12 years ago -
Thanks Dugullett, Client is insisting on VB or Batch script. Is there a way I can convert your script to VB or batch and use it. Please guide me..
Thanks.. - shamu99 12 years ago -
You can use http://www.f2ko.de/programs.php?lang=en&pid=b2e to convert to an exe.
Enter "powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file script.ps1" as your cmd line.
It would still utilize Powershell though. I've never done anything like this using any but Powershell. So I don't know if it is possible. - dugullett 12 years ago -
I did download the batch to exe. so now I need to create a batch file with this "powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file script.ps1"? how is it? Sorry, not good with powershell :P - shamu99 12 years ago
-
Save the above script as script.ps1. Under the "include" tab in the converter add script.ps1.
I checked under options "invisible, delete at exit, overwrite existing, and temp dir". This will create an exe of this script.
This will still need powershell on the machine for it to run. It should be there if the machines are fully patched. - dugullett 12 years ago