{"id":1727,"date":"2021-04-25T00:00:00","date_gmt":"2021-04-24T15:00:00","guid":{"rendered":"https:\/\/www.ishikawasekkei.com\/?p=1727"},"modified":"2021-04-24T12:08:22","modified_gmt":"2021-04-24T03:08:22","slug":"python-programing-windows-shortcut-change-server-name","status":"publish","type":"post","link":"https:\/\/www.ishikawasekkei.com\/index.php\/2021\/04\/25\/python-programing-windows-shortcut-change-server-name\/","title":{"rendered":"Python \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 Windows\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u53c2\u7167\u5148\u30b5\u30fc\u30d0\u540d\u306e\u5909\u66f4"},"content":{"rendered":"\n<p>\u3000\u898b\u306b\u6765\u3066\u304f\u3060\u3055\u3063\u3066\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u305f\u304f\u3055\u3093\u3042\u3063\u305fWindows\u306e\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u53c2\u7167\u5148\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f7f\u3063\u3066\u4e00\u6c17\u306b\u5909\u3048\u305f\u304f\u306a\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3084\u308a\u65b9\u304c\u3059\u3050\u306b\u898b\u3064\u3051\u3089\u308c\u306a\u304b\u3063\u305f\u306e\u3067\u8a18\u9332\u3057\u3066\u304a\u304d\u307e\u3059\u3002\u30b5\u30fc\u30d0\u306e\u30ea\u30d7\u30ec\u30fc\u30b9\u3084\u30d5\u30a9\u30eb\u30c0\u306e\u6574\u7406\u7b49\u306b\u3088\u308a\u3001\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u53c2\u7167\u5148\u304c\u5909\u308f\u3063\u3066\u3057\u307e\u3063\u3066\u5bfe\u5fdc\u304c\u5fc5\u8981\u306b\u306a\u3063\u305f\u3068\u304d\u306b\u4f7f\u3048\u307e\u3059\u3002\u3069\u306a\u305f\u304b\u306e\u304a\u5f79\u306b\u7acb\u3066\u3070\u3001\u3046\u308c\u3057\u3044\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3000\u3059\u3050\u306b\u898b\u3064\u3051\u3089\u308c\u306a\u304b\u3063\u305f\u306e\u306f\u3001\u300c\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u300d\u3068\u3044\u3046\u540d\u79f0\u304c\u3088\u304f\u306a\u304b\u3063\u305f\u3088\u3046\u3067\u3059\u3002\u30ad\u30fc\u30dc\u30fc\u30c9\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u304c\u691c\u7d22\u7d50\u679c\u306e\u4e0a\u4f4d\u306b\u767b\u5834\u3057\u3066\u304d\u307e\u3059\u3002\u8a66\u884c\u932f\u8aa4\u3057\u3066\u63a2\u3057\u51fa\u3057\u307e\u3057\u305f\u304c\u3001\u307e\u305a\u306f\u53c2\u8003\u306b\u306a\u3063\u305f\u306e\u304c<a href=\"https:\/\/stackoverflow.com\/questions\/397125\/reading-the-target-of-a-lnk-file-in-python\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"https:\/\/stackoverflow.com\/questions\/397125\/reading-the-target-of-a-lnk-file-in-python\">\u3053\u3061\u3089<\/a>\u3067\u3059\u3002\u3053\u3053\u3067\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u62e1\u5f35\u5b50\u306f\u300c.lnk\u300d\u3089\u3057\u3044\u3001\u3068\u3044\u3046\u3053\u3068\u3068\u3001win32com.client\u306eDispatch\u3067&#8221;WScript.Shell&#8221;\u3092\u4f7f\u3048\u3070\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u304c\u4f5c\u6210\u3067\u304d\u308b\u3089\u3057\u3044\u3001\u3068\u3001\u30a2\u30bf\u30ea\u3092\u3064\u3051\u307e\u3057\u305f\u3002<br>\u3000\u4eca\u56de\u306f\u3001\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u300c\u30ea\u30f3\u30af\u5148(T)\u300d\u300c\u4f5c\u696d\u30d5\u30a9\u30eb\u30c0\u30fc(S)\u300d\u3092\u4fee\u6b63\u3057\u305f\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u4e0a\u8a18\u3067\u898b\u3064\u3051\u305f\u30ea\u30f3\u30af\u3067\u306f\u300c\u30ea\u30f3\u30af\u5148(T)\u300d\u304c\u300cTargetPath\u300d\u3060\u3001\u3068\u3044\u3046\u3053\u3068\u3057\u304b\u308f\u304b\u3089\u306a\u304b\u3063\u305f\u306e\u3067\u3001\u8ffd\u52a0\u3067\u300cWScript.Shell\u300d\uff0b\u300cshortcut\u300d\uff0b\u300cproperty\u300d\u3067\u691c\u7d22\u3057\u3066<a href=\"https:\/\/www.atmarkit.co.jp\/ait\/articles\/0712\/27\/news083_2.html\" target=\"_blank\" rel=\"noreferrer noopener\">\u3053\u3061\u3089\u306e\u30da\u30fc\u30b8<\/a>\u3092\u898b\u3064\u3051\u307e\u3057\u305f\u3002\u3053\u3061\u3089\u3067\u300c\u4f5c\u696d\u30d5\u30a9\u30eb\u30c0\u30fc(S)\u300d\u306f\u300cWorkingDirectory\u300d\u3068\u3044\u3046\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"955\" src=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2021\/04\/image-1.png\" alt=\"\" class=\"wp-image-1732\" srcset=\"https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2021\/04\/image-1.png 602w, https:\/\/www.ishikawasekkei.com\/wp-content\/uploads\/2021\/04\/image-1-189x300.png 189w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><figcaption>\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n\n\n\n<p>\u3000\u3053\u3053\u307e\u3067\u308f\u304b\u308c\u3070\u306a\u3093\u3068\u304b\u306a\u308b\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002Python\u3067\u3059\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!python\n# -*- coding: cp932 -*-\n# \u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u6307\u5b9a\u3057\u305f\u30d5\u30a9\u30eb\u30c0\u306e\u4e2d\u3092\u304f\u307e\u306a\u304f\u64cd\u4f5c\u3057\u3066\u3001\n# \u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u3092\u898b\u3064\u3051\u305f\u3068\u304d\u306b\u3001\u300c\u7f6e\u304d\u63db\u3048\u524d\u300d\u3092\u300c\u7f6e\u304d\u63db\u3048\u5f8c\u300d\u306b\u7f6e\u304d\u63db\u3048\u308b\u305f\u3081\u306b\u3064\u304f\u308a\u307e\u3057\u305f\u3002\n# \u5909\u6570\u3092\u5909\u66f4\u3059\u308b\u3053\u3068\u3067\u4ed6\u306e\u7528\u9014\u306b\u3082\u5bfe\u5fdc\u53ef\u80fd\u3067\u3059\u3002\n\nimport os\nimport win32com.client \n\n\u6307\u5b9a\u30d5\u30a9\u30eb\u30c0 = \"Z:\" + os.sep + \"\u30c6\u30b9\u30c8\u30d5\u30a9\u30eb\u30c0\"\n\u7f6e\u304d\u63db\u3048\u524d = r\"\\\\old_server\" + os.sep + \"shared_folder$\"\n\u7f6e\u304d\u63db\u3048\u5f8c = r\"\\\\new_server\" + os.sep + \"shared_folder$\"\n\nshell = win32com.client.Dispatch(\"WScript.Shell\")\n\nfor root, dirs, files in os.walk(\u6307\u5b9a\u30d5\u30a9\u30eb\u30c0):\n    for file in files:\n        if file[-4:] == \".lnk\":\n            shortcut = shell.CreateShortCut(root + os.sep + file)\n            if shortcut.Targetpath[:len(\u7f6e\u304d\u63db\u3048\u524d)].lower() == \u7f6e\u304d\u63db\u3048\u524d.lower():\n                changed_targetpath = \u7f6e\u304d\u63db\u3048\u5f8c + shortcut.Targetpath[len(\u7f6e\u304d\u63db\u3048\u524d):]\n                shortcut.Targetpath = changed_targetpath\n                shortcut.save()\n            if shortcut.Workingdirectory[:len(\u7f6e\u304d\u63db\u3048\u524d)].lower() == \u7f6e\u304d\u63db\u3048\u524d.lower():\n                changed_workingdirectory = \u7f6e\u304d\u63db\u3048\u5f8c + shortcut.Workingdirectory[len(\u7f6e\u304d\u63db\u3048\u524d):]\n                shortcut.Workingdirectory = changed_workingdirectory\n                shortcut.save()\n<\/pre>\n\n\n\n<p>\u3000\u307e\u305a\u306f\u3001\u4e00\u756a\u306e\u30dd\u30a4\u30f3\u30c8\u300114\u884c\u76ee\u306eWScript.Shell\u3067\u3059\u306d\u3002\u3053\u3053\u3067\u306fCOM\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u30c7\u30a3\u30b9\u30d1\u30c3\u30c1\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308aWindows\u306eWshShell\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6a5f\u80fd\u304c\u5229\u7528\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<br>\u3000\u6b21\u306f16\u884c\u76ee\u3067\u3059\u304c\u3001os.walk\u3092\u5229\u7528\u3057\u3066\u3001\u300c\u6307\u5b9a\u30d5\u30a9\u30eb\u30c0\u300d\u914d\u4e0b\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u3059\u3079\u3066\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002\u3053\u3053\u306efor\u30eb\u30fc\u30d7\u306eroot\u306b\u3001\u73fe\u5728\u51e6\u7406\u5bfe\u8c61\u306e\u30d5\u30a9\u30eb\u30c0\u540d\u3001files\u306b\u305d\u306e\u30d5\u30a9\u30eb\u30c0\u5185\u306b\u3042\u308b\u30d5\u30a1\u30a4\u30eb\u306e\u30ea\u30b9\u30c8\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002\u3053\u306e\u53d6\u5f97\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u30ea\u30b9\u30c8\u3092\u3059\u3079\u3066\u51e6\u7406\u3057\u59cb\u3081\u308b\u306e\u304c\u300117\u884c\u76ee\u306efor\u30eb\u30fc\u30d7\u3067\u3059\u3002<br>\u300018\u884c\u76ee\u3067\u306f\u3001\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u6700\u5f8c\u306e4\u6587\u5b57\u3092\u53d6\u308a\u51fa\u3057\u3066\u300c.lnk\u300d\u304b\u3069\u3046\u304b\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3044\u307e\u3059\u3002\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306f\u62e1\u5f35\u5b50\u304c\u300c.lnk\u300d\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\u305d\u3057\u3066\u3001\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u5834\u5408\u300119\u884c\u76ee\u3067\u300cCreateShortCut\u300d\u3092\u4f7f\u3063\u3066\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u4f5c\u6210\u3059\u308b\u3001\u3068\u8a00\u3063\u3066\u3082\u5143\u3005\u304c\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u3067\u3059\u306e\u3067\u3001\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u304c\u65b0\u3057\u304f\u4f5c\u6210\u3055\u308c\u308b\u308f\u3051\u3067\u306f\u306a\u304f\u3001\u73fe\u5728\u306e\u8a2d\u5b9a\u306e\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u3092\u53c2\u7167\u3057\u305f\u5f62\u306b\u306a\u308a\u307e\u3059\u3002\u3061\u306a\u307f\u306b\u3001os.sep\u306f\u3001\u30bb\u30d1\u30ec\u30fc\u30c8\u6587\u5b57\u5217\u3067\u3001Windows\u306e\u5834\u5408\u300c\\\u300d\u3001Linux\u306e\u5834\u5408\u306f\u300c\/\u300d\u306e\u3088\u3046\u306b\u9069\u5207\u306a\u533a\u5207\u308a\u6587\u5b57\u306b\u30bb\u30c3\u30c8\u3055\u308c\u307e\u3059\u3002<br>\u300020\u884c\u76ee\u3067\u7f6e\u304d\u63db\u3048\u5bfe\u8c61\u304b\u3069\u3046\u304b\u30c1\u30a7\u30c3\u30af\u3057\u3066\u3001\u5bfe\u8c61\u306a\u3089\u300cTargetpath\u300d\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3053\u3068\u3067\u300c\u30ea\u30f3\u30af\u5148\u300d\u3092\u66f4\u65b0\u3057\u306623\u884c\u76ee\u306e\u300csave\u300d\u30e1\u30bd\u30c3\u30c9\u3067\u5909\u66f4\u3092\u78ba\u5b9a\u3059\u308b\u3001\u3068\u3044\u3046\u3053\u3068\u3092\u3084\u3063\u3066\u3044\u307e\u3059\u300224\uff5e27\u884c\u306f\u540c\u69d8\u3067\u3059\u304c\u3001\u300cWorkingDirectory\u300d\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3053\u3068\u3067\u300c\u4f5c\u696d\u30d5\u30a9\u30eb\u30c0\u30fc\u300d\u3092\u66f4\u65b0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u307e\u3068\u3081<\/h2>\n\n\n\n<p>\u3000\u3000\u3084\u308a\u305f\u3044\u3053\u3068\u306f\u96e3\u3057\u3044\u3053\u3068\u3067\u306a\u304b\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u65e2\u5b58\u306e\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u3092\u66f4\u65b0\u3057\u305f\u3044\u306e\u306b\u300cCreateShortCut\u300d\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u3001\u3068\u3044\u3046\u3068\u3053\u308d\u304c\u3061\u3087\u3063\u3068\u99b4\u67d3\u3081\u306a\u3044\u611f\u3058\u304c\u3057\u307e\u3057\u305f\u3002\u307e\u3001\u6163\u308c\u308c\u3070\u5927\u4e08\u592b\u3067\u3059\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u898b\u306b\u6765\u3066\u304f\u3060\u3055\u3063\u3066\u3001\u3042\u308a\u304c\u3068\u3046\u3054\u3056\u3044\u307e\u3059\u3002\u77f3\u5ddd\u3055\u3093\u3067\u3059\u3002 \u3000\u305f\u304f\u3055\u3093\u3042\u3063\u305fWindows\u306e\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u53c2\u7167\u5148\u3092\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f7f\u3063\u3066\u4e00\u6c17\u306b\u5909\u3048\u305f\u304f\u306a\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3084\u308a\u65b9\u304c\u3059\u3050\u306b\u898b\u3064\u3051\u3089\u308c\u306a\u304b\u3063\u305f\u306e\u3067\u8a18\u9332\u3057\u3066\u304a\u304d\u307e\u3059\u3002\u30b5 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.ishikawasekkei.com\/index.php\/2021\/04\/25\/python-programing-windows-shortcut-change-server-name\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Python \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0 Windows\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u306e\u53c2\u7167\u5148\u30b5\u30fc\u30d0\u540d\u306e\u5909\u66f4&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,2],"tags":[],"class_list":["post-1727","post","type-post","status-publish","format-standard","hentry","category-program","category-blog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1727","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/comments?post=1727"}],"version-history":[{"count":6,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1727\/revisions"}],"predecessor-version":[{"id":1735,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/posts\/1727\/revisions\/1735"}],"wp:attachment":[{"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/media?parent=1727"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/categories?post=1727"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ishikawasekkei.com\/index.php\/wp-json\/wp\/v2\/tags?post=1727"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}