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

北城余情 提交于 2019-12-10 10:54:19

问题


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?


回答1:


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()


来源:https://stackoverflow.com/questions/15621294/how-to-run-windows-command-mklink-from-vb-net-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!