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.

Cancel

2

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=0ICASOCKSProxyPortNumber=0ICASOCKSTimeout=0"

$text2 = " [Program Neighborhood]" if ($ini -eq $null) {add-content$output "$text"} else {continue} if ($ini2 -eq $null) {add-content$output "$text2"} else {exit} Answered 05/30/2012 by: dugullett • This content is currently hidden from public view. Reason: Removed by user request For more information, visit our FAQ's. • Excellent, thank you so much. Users machine does not recognise the powershell script. So client prefers a Batch or VBS.. Thanks again • What do you mean doesn't recognize? What OS is it? • This content is currently hidden from public view. Reason: Removed by user request For more information, visit our FAQ's. • Oh.... Well that sucks. Well save this script for 2014. Then you'll have no other choice. • lol , thanks for your help again Please log in to comment Answers 1 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. Answered 05/29/2012 by: philologist Please log in to comment 0 Are you wanting to change just the name, or the actual contents of the file? Answered 05/29/2012 by: dugullett Please log in to comment 0 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.... Answered 05/29/2012 by: shamu99 Please log in to comment 0 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}

• This content is currently hidden from public view.
Reason: Removed by user request
• 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}
• 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.
0

If you use MSI, and then ini table in there, you will just be able to edit the ini rather than overwriting it.

0

Hi all,

Is it possible for me to create the script with a batch or VBscript..

Any help is appreciated.

• This content is currently hidden from public view.
Reason: Removed by user request
• Can you run this update? You need SP3.
• 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..
• 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.
• 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
• 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.