0

...using Windows 7...

I have a sqlserver.exe.config file that needs to get copied to the SQL Server BINN directory on my local machine (for the SQLExpress instance).

I can't assume the location, so I poked around in the registry and found

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\Setup "sqlpath"

So in a CMD I would like to get the value of that and then copy the file to that place. The reason I need to do it in CMD is because this should be in a post-build event. Can anyone recommend how to do this with REG or anything else?

Thanks.

1 Answer 1

1

You've got many solutions.

1. You want to work in th old CMD fashion

You can use REG.EXE command line program :

C:\silogix>reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fax" /v ArchiveFolder

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fax
    ArchiveFolder    REG_SZ    C:\ProgramData\Microsoft\Windows NT\MSFax

Y'll fin in an other article how to split the response.

2. With Powershell

In PowerShell command line (or script) you can access the registry like a drive :

PS C:\silogix> (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Fax").ArchiveFolder
C:\ProgramData\Microsoft\Windows NT\MSFax

It's shorter to write. Registry keys are items and values are properties. PowerShell is a powerfull command line interpreter (you can use for scripting) which is on the top of .NET Framework. It makes scripting easy for C# programmers.

JP

Sign up to request clarification or add additional context in comments.

3 Comments

I like the PowerShell option. Then I googled all over the place trying to figure out how to get the PS output back into CMD so I can use it. Any ideas?
You can call your .PS1 file with th -F in your PS1 you can format your output with out-host, out-string or out-file.
powershell.exe -noprofile (Get-ItemProperty -Path "'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\SQLEXPRESS\Setup'").SqlPath I am having a hard time trapping that with -F which I think is for numbers?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.