简体   繁体   中英

How to run windows command “mklink” from vb.net application?

I want to be able to run "mklink path1 path2" from my vb.net project. I fail to do that. I have tried with Shell() function and with Process.

With this it only open cmd.exe window and does nothing:

        Dim process As New Process
        process.StartInfo.FileName = "cmd.exe"
        process.StartInfo.Arguments = "mklink """ + arma2oaAddons + """ """ + arma2Addons + """ /j"
        process.StartInfo.WorkingDirectory = "C:\"
        process.Start()

And with this I get error "File not found". It can't find mklink.:

        Shell("mklink """ + arma2oaAddons + """ """ + arma2Addons + """ /j")

What is mklink?

Mklink is a MS Windows command line utility that you can use to create symbolic links or symlinks and hard links in MS Windows. It's a part of CMD shell such as dir command.

How do I do this correctly?

the first example if fine except you need to use cmd.exe /c if you want it to be executed so

Dim process As New Process
process.StartInfo.FileName = "cmd.exe"
process.StartInfo.Arguments = "/c mklink """ + arma2oaAddons + """ """ + arma2Addons + """ /j"
process.StartInfo.WorkingDirectory = "C:\"
process.Start()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM