2013년 1월 4일 금요일

exe 실행하기


$xFilePath = "D:\nexusfile\"

$excute = $xFilePath + "x.exe"

&$excute

머 이렇게 하면 excute함수가 실행된다 & 붙여야되는것을 몰랐던것이다... ㅋㅋ


아 참고로 아귀먼트가 있으면

$excute = "notepad.exe"
$arg = "readme_ko.txt"

&$excute $arg

이런식으로 하면 된다... 바보 같이 

$excute = "noepad.exe readme_ko.txt" 이렇게 해서 실행하면 안된다.

레지스트리 조작 부팅시 start-up 프로그램 지정

################################################################## 
 
# 부팅시 Install2를 자동으로 실행한다.

################################################################# 

param
(
[string]$ParamOption
)

Function StartUpInstall
{
param([string]$ParamOption )
$RegStartUp= "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" 
if ($ParamOption -eq "/u")
{
Remove-ItemProperty $RegStartUp -Name Install
}
else 
{
Set-ItemProperty $RegStartUp -Name Install -Value c:\setup\install2.bat
}
}

StartUPInstall $ParamOption



Remove-ItemProperty $RegStartUp -Name Install = regkey를 지우는것

Set-ItemProperty $RegStartUp -Name Install -Value c:\setup\install2.bat  = regkey 수정이나 추가할때 쓰인다.


startup 출처: http://blog.scorpiotek.com/2008/12/31/how-to-create-startup-items-on-server-core/

Powershell 에서 XML Encoding 관련.


-encoding UTF8 이거 앞에 붙여야 에러가 안난다 꼭 인코딩을 신경쓰자


[xml] $XmlContent = Get-Content "c:\web.config" -encoding UTF8

echo $XmlContent.configuration.'system.serviceModel'.services.service.host.baseAddresses.add

echo $XmlContent.configuration.'system.serviceModel'.services.service.endpoint.address

이렇게 xml을 불러올올수 있고 노드를 찾아가면 된다. 만약 " . "이 있을경우 ' '로 묶으면 된다...

저렇게 되면 해당 노드값을 출력할수 있다.

수정및 저장은
$XmlContent.configuration.'system.serviceModel'.services.service.host.baseAddresses.add.baseAddress = "http://172.16.10.99:21000/MessageService.svc"
$XmlContent.configuration.'system.serviceModel'.services.service.endpoint.address = "net.tcp://172.16.10.99:20000/MessageService.svc"
$xmlContent.Save("c:\web.config")

머 이렇게 save를 하니까 잘되었다 하지만 인코딩이 좀 이상하다 확인해보아야할 부분이다.

powershll xml control에 대한 정보는 여기서 많이 얻을수 있다.
http://powershell.com/cs/blogs/tobias/archive/2009/02/02/xml-part-2-write-add-and-change-xml-data.aspx

출처 : http://hackss.tistory.com/entry/ps-xml-file-control-%ED%95%98%EA%B8%B0