以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]如何用代码打开共享目录  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=116650)

--  作者:nbsfy
--  发布时间:2018/3/28 20:07:00
--  [求助]如何用代码打开共享目录
作为服务器的电脑(win2012)上设置了共享目录,\\\\fwq\\asd   打开需输入用户名(user)和密码(123)!
如何用代码打开这个目录

--  作者:有点甜
--  发布时间:2018/3/28 20:23:00
--  

beforeOpenProject写代码

 

Dim p As new Process()
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.UseShellExecute = False \'关闭Shell的使用
p.StartInfo.RedirectStandardInput = True \'重定向标准输入
p.StartInfo.RedirectStandardOutput = True \'重定向标准输出
p.StartInfo.RedirectStandardError = True \'重定向错误输出
p.StartInfo.CreateNoWindow = True \'设置不显示窗口
p.Start()
p.StandardInput.WriteLine( "net use * /del /y")
p.StandardInput.WriteLine( "net use \\\\fwq\\asd 密码 /user:用户名")     
p.StandardInput.WriteLine("exit")
[此贴子已经被作者于2018/3/30 14:31:35编辑过]

--  作者:有点甜
--  发布时间:2018/3/28 20:23:00
--  

打开某个目录,参考代码

 

http://www.foxtable.com/webhelp/scr/0353.htm

 


--  作者:nbsfy
--  发布时间:2018/3/28 20:36:00
--  
感谢!
我去试下!

--  作者:nbsfy
--  发布时间:2018/3/29 18:02:00
--  
Dim p As new Process()
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.UseShellExecute = False \'关闭Shell的使用
p.StartInfo.RedirectStandardInput = True \'重定向标准输入
p.StartInfo.RedirectStandardOutput = True \'重定向标准输出
p.StartInfo.RedirectStandardError = True \'重定向错误输出
p.StartInfo.CreateNoWindow = True \'设置不显示窗口
p.Start()
p.StandardInput.WriteLine( "net use \\\\fwq\\abc qwe /user:asd")     
p.StandardInput.WriteLine("exit")

If FileSys.DirectoryExists("\\\\fwq\\abc\\") Then     
Else
    e.Cancel=True
    msgbox("主机休眠中,无法连接数据库" )
End

第一次打开,显示  主机休眠中,无法连接数据库  
再打开,就能进去了!
是不是,代码位置放的不对!
[此贴子已经被作者于2018/3/29 18:17:04编辑过]

--  作者:有点甜
--  发布时间:2018/3/29 18:07:00
--  

1、找不到表?什么意思?你的提问和【找不到表】有什么关系,截图看看。

 

2、具体一点你的问题,怎么操作,出现什么情况,你本来要做什么功能?


--  作者:nbsfy
--  发布时间:2018/3/29 18:18:00
--  
我把代码放上来了!
我是放在BeforeOpenProject 里的!
[此贴子已经被作者于2018/3/29 18:20:14编辑过]

--  作者:有点甜
--  发布时间:2018/3/29 18:23:00
--  

试试改成

 


Dim p As new Process()
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.UseShellExecute = False \'关闭Shell的使用
p.StartInfo.RedirectStandardInput = True \'重定向标准输入
p.StartInfo.RedirectStandardOutput = True \'重定向标准输出
p.StartInfo.RedirectStandardError = True \'重定向错误输出
p.StartInfo.CreateNoWindow = True \'设置不显示窗口
p.Start()
p.StandardInput.WriteLine( "net use * /del /y")
p.StandardInput.WriteLine( "net use \\\\fwq\\abc qwe /user:asd")
p.StandardInput.WriteLine("exit")
system.threading.thread.sleep(1000)
If FileSys.DirectoryExists("\\\\fwq\\abc\\") Then
   
Else
    e.Cancel=True
    msgbox("主机休眠中,无法连接数据库" )
End If


--  作者:nbsfy
--  发布时间:2018/3/30 12:08:00
--  
再请教,程序运行中,要再换个更高权限的登陆名!
代码能否实现!

--  作者:有点甜
--  发布时间:2018/3/30 12:15:00
--  
以下是引用nbsfy在2018/3/30 12:08:00的发言:
再请教,程序运行中,要再换个更高权限的登陆名!
代码能否实现!

 

如果要修改代码,需要替换原来的程序,才可以的。

 

你什么时候需要重新登陆进去,那就再什么时候执行2楼代码。