{"id":2276,"date":"2016-02-16T14:26:42","date_gmt":"2016-02-16T05:26:42","guid":{"rendered":"http:\/\/www23.atpages.jp\/~inoni\/?p=2276"},"modified":"2017-10-20T17:27:01","modified_gmt":"2017-10-20T08:27:01","slug":"excelvba%e8%a6%9a%e6%9b%b8-shell%e3%81%a8%e3%81%8b%e3%83%aa%e3%83%a2%e3%83%bc%e3%83%88%e5%ae%9f%e8%a1%8c%e3%81%a8%e3%81%8b","status":"publish","type":"post","link":"http:\/\/anada.cloudfree.jp\/?p=2276","title":{"rendered":"ExcelVBA\u899a\u66f8 Shell\u3068\u304b\u30ea\u30e2\u30fc\u30c8\u5b9f\u884c\u3068\u304b"},"content":{"rendered":"<p>\u5fd8\u308c\u308b\u524d\u306b\u30e1\u30e2\u3063\u3068\u304f\u3002<br \/>\nVBA\u304b\u3089\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3092\u975e\u540c\u671f\u3067\u884c\u3046\u6642\u306b\u4f7f\u3046Shell\u95a2\u6570\u3002<br \/>\n\u7b2c2\u5f15\u6570\u306bvbMinimizedNoFocus\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u306f\u975e\u8868\u793a\u306b\u306a\u3063\u3066\u3001\u88cf\u5074\u3067\u8d70\u308b\u4ed5\u7d44\u307f\u306b\u3067\u304d\u308b\u305d\u3046\u306a\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nDim cmd_buf As String\nDim res     As Double\n\ncmd_buf = &quot;cmd \/c sqlcmd -S {DB-Source} -U {DB-UserId} -P {DB-UserPw} -d {DB-Name} &quot; _\n         &amp; &quot; -Q &quot;&quot;EXEC {\u30d7\u30ed\u30b7\u30fc\u30b8\u30e3\u540d} {*}, '{*}' &quot;&quot;&quot; \nres = Shell(cmd_buf, vbMinimizedNoFocus)\n<\/pre>\n<p>{}\u66f8\u304d\u306f\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u5909\u66f4<br \/>\n{*}\u306f\u30b9\u30c8\u30a2\u30c9\u306e\u5f15\u6570\u3067\u3001\u6587\u5b57\u5217\u306e\u5834\u5408\u306f\u30b7\u30f3\u30b0\u30eb\u30af\u30a9\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3067\u56f2\u3080\u3002<\/p>\n<p>Shell\u306e\u623b\u308a\u5024\u306f\u30bf\u30b9\u30afID\u3067\u3001\u300c0\u300d\u304c\u304b\u3048\u3063\u3066\u304d\u305f\u3089\u52d5\u3044\u3066\u3044\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u3089\u3057\u3044\u3002<br \/>\n\u975e\u540c\u671f\u306a\u306e\u3067\u52dd\u624b\u306b\u52d5\u3044\u3066\u3001\u52dd\u624b\u306b\u7d42\u308f\u308b\u3002<\/p>\n<p>\u7d42\u308f\u3063\u305f\u3089\u30a6\u30a3\u30f3\u30c9\u30a6\u3092\u30a2\u30af\u30c6\u30a3\u30d6\u306b\u3059\u308b\u3068\u304b\u3059\u308b\u3068\u3001\u7d42\u308f\u3063\u305f\u3053\u3068\u304c\u308f\u304b\u308b\u3089\u3057\u3044\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nIf res &gt; 0 Then Call AppActivate(res)\n<\/pre>\n<p>\u3068\u3001\u3053\u3093\u306a\u611f\u3058\u304b\u306d\u3002<br \/>\n\u3075\u3080\u3075\u3080\u3001\u3057\u304b\u3057\u3060\u306d\u3001\u88cf\u5074\u3067\u52dd\u624b\u306b\u52d5\u3044\u3066\u3044\u308b\u308f\u3051\u3067\u3001\u4e0b\u624b\u306bPC\u30b7\u30e3\u30c3\u30c8\u30c0\u30a6\u30f3\u3057\u3061\u3083\u3046\u3068\u3001\u51e6\u7406\u304c\u9014\u4e2d\u3067\u7d42\u308f\u3063\u3061\u3083\u3046\uff01\u3063\u3066\u3068\u3053\u308d\u304c\u6016\u3044\u3002<\/p>\n<p>\u3067\u3001\u6b21\u3002<br \/>\n\u30ea\u30e2\u30fc\u30c8\u74b0\u5883\u306b\u3042\u308b\u30d0\u30c3\u30c1\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3059\u308b\u65b9\u6cd5\u3002<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\n'server\uff1a\u30ea\u30e2\u30fc\u30c8\u30b5\u30fc\u30d0(user_id\/user_pw\u3067\u30ed\u30b0\u30a4\u30f3)\n'exe_name\uff1a\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb, exe_position\uff1a\u5b9f\u884c\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\nPublic Function ExecuteRemoteExe(server As String, user_id As String, user_pw As String _\n                                , exe_name As String, exe_position As String) As Boolean\n\n    Const AUTHENTICATION_LEVEL_PKT_PRIVACY = 6\n    \n    Dim obj_locator As Object\n    Dim obj_server  As Object\n    Dim obj_process As Object\n    Dim res As Long\n    Dim pid As Long\n    \n    On Error GoTo ErrExecute\n    \n    Set obj_locator = CreateObject(&quot;WbemScripting.SWbemLocator&quot;)\n    Set obj_server = obj_locator.ConnectServer(server, &quot;root\\cimv2&quot;, user_id, user_pw)\n    obj_server.Security_.authenticationLevel = AUTHENTICATION_LEVEL_PKT_PRIVACY\n    \n    Set obj_process = server.get(&quot;Win32_Process&quot;)\n    res = obj_process.Create(exe_position, Null, Null, pid)\n\n    Select Case res\n        Case 0\n            ExecuteRemoteExe = True\n        Case 2\n            Msgbox &quot;\u30a2\u30af\u30bb\u30b9\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot;\n        Case 9\n            Msgbox &quot;\u30d1\u30b9\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002&quot; \n        Case 21\n            Msgbox &quot;\u30d1\u30e9\u30e1\u30fc\u30bf\u304c\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002&quot;\n        Case Else\n            Msgbox &quot;\u30d0\u30c3\u30c1\u3092\u5b9f\u884c\u3067\u304d\u307e\u305b\u3093\u3067\u3057\u305f\u3002&quot;  \n    End Select\n        \nErrExecute:\n    \n    Set obj_process = Nothing\n    Set obj_server = Nothing\n    Set obj_locator = Nothing\n    \nEnd Function\n<\/pre>\n<p>\u3053\u308c\u3067\u30ea\u30e2\u30fc\u30c8\u306e\u30d0\u30c3\u30c1\u30d5\u30a1\u30a4\u30eb\u3092\u5b9f\u884c\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002<br \/>\n\u3067\u304d\u308b\u3093\u3060\u3051\u3069\u3001\u3053\u308c\u3082\u3053\u3063\u3061\u5074\u306ePC\u3092\u5207\u3063\u3066\u3057\u307e\u3046\u3068\u3001\u30d0\u30c3\u30c1\u3082\u7d42\u308f\u3063\u3066\u3057\u307e\u3046\u30fb\u30fb\u30fb<br \/>\n\u306a\u3093\u3068\u304b\u306a\u3089\u3093\u304b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5fd8\u308c\u308b\u524d\u306b\u30e1\u30e2\u3063\u3068\u304f\u3002 VBA\u304b\u3089\u30b3\u30de\u30f3\u30c9\u5b9f\u884c\u3092\u975e\u540c\u671f\u3067\u884c\u3046\u6642\u306b\u4f7f\u3046Shell\u95a2\u6570\u3002 \u7b2c2\u5f15\u6570\u306bvbMinimizedNoFocus\u3092\u8a2d\u5b9a\u3059\u308b\u3068\u3001\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u306f\u975e\u8868\u793a\u306b\u306a\u3063\u3066\u3001\u88cf\u5074\u3067\u8d70\u308b\u4ed5\u7d44\u307f\u306b\u3067\u304d\u308b\u305d\u3046\u306a\u3002 Di [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[43,74],"class_list":["post-2276","post","type-post","status-publish","format-standard","hentry","category-excelvba","tag-excel","tag-vba"],"_links":{"self":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2276","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2276"}],"version-history":[{"count":1,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2276\/revisions"}],"predecessor-version":[{"id":2665,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=\/wp\/v2\/posts\/2276\/revisions\/2665"}],"wp:attachment":[{"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2276"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2276"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/anada.cloudfree.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2276"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}