您的位置:程序门 -> vb -> 网络编程



如何通过wmi写入一个bat文件并执行?


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


如何通过wmi写入一个bat文件并执行?[已结贴,结贴人:ngela]
发表于:2007-02-20 10:10:56 楼主
用何用vb通过wmi远程写入bat文件并执行呀?
发表于:2007-02-20 10:59:001楼 得分:100
试试看  

option   explicit
dim   objswbemlocator   as   new   swbemlocator
dim   objswbemservices   as   swbemservices
dim   objswbemobjectset   as   swbemobjectset
dim   objswbemobject   as   swbemobject,   objstartup   as   swbemobject,   objconfig   as   swbemobject
dim   strcomputer   as   string,   strusername   as   string,   strpassword   as   string,   strcommand   as   string
private   const   sw_normal   =   1

private   sub   form_load()
        me.caption   =   "启动进程 "
        strcomputer   =   ". "       '.为本机,可以指定远程计算机
        strusername   =   " "         '指定计算机的管理员帐号
        strpassword   =   " "         '指定计算机的管理员口令
        strcommand   =   "cmd   /k   dir "   '命令行方式或一个可以带路径的可执行程序例如 "c:\winnt\system32\notepad.exe "
        set   objswbemservices   =   objswbemlocator.connectserver(strcomputer,   "root\cimv2 ",   strusername,   strpassword)   '连接到本机的wmi,返回一个对   swbemservices   对象的引用
end   sub

private   sub   command1_click()
dim   intreturn   as   long,   intprocessid   as   long
        '构造进程的作为窗口显示
        set   objstartup   =   objswbemservices.get( "win32_processstartup ")
        set   objconfig   =   objstartup.spawninstance_
        objconfig.showwindow   =   sw_normal
        '   建立进程
        set   objswbemobject   =   objswbemservices.get( "win32_process ")
        intreturn   =   objswbemobject.create(strcommand,   null,   objconfig,   intprocessid)
        if   intreturn   <>   0   then
                msgbox   strcommand   &   "进程不能被创建! "   &   _
                        vbcrlf   &   "command   line:   "   &   strcommand   &   _
                        vbcrlf   &   "return   value:   "   &   intreturn
        else
                msgbox   strcommand   &   "进程已创建: "   &   _
                        vbcrlf   &   "command   line:   "   &   strcommand   &   _
                        vbcrlf   &   "process   id:   "   &   intprocessid
        end   if
end   sub

   

发表于:2007-02-22 23:34:012楼 得分:0
看不明白,例如我要写入一个bat文件到网络上的机子,并执行,应该怎么改?


快速检索

最新资讯
热门点击