[{"data":1,"prerenderedAt":1084},["ShallowReactive",2],{"blog-\u002Fblog\u002F2023\u002F12\u002Fdevice-agent-as-a-windows-service":3},{"id":4,"title":5,"body":6,"description":12,"extension":1068,"meta":1069,"navigation":1079,"path":1080,"seo":1081,"stem":1082,"__hash__":1083},"blog\u002Fblog\u002F2023\u002F12\u002Fdevice-agent-as-a-windows-service.md","Run Node-RED as a service on Windows",{"type":7,"value":8,"toc":1036},"minimark",[9,13,24,29,37,41,44,47,57,60,77,90,97,104,112,117,130,134,160,164,178,182,186,194,197,201,212,216,224,300,309,313,322,332,445,454,461,517,521,532,543,547,553,574,581,585,588,591,610,623,651,663,667,674,692,696,699,747,758,770,774,781,785,884,888,891,900,903,910,925,929,932,946,953,960,966,970,973,987,990,1002,1005,1019,1023,1032],[10,11,12],"p",{},"FlowFuse's device agent allows you to manage and run your Node-RED instances on\nyour own hardware such as a Raspberry Pi or Windows computer. This can be very useful where an\napplication you've written needs to run flows with direct access to hardware sensors.",[10,14,15,16,23],{},"In this article, we're going to explain the steps to configure our device agent to run as a service in Windows\nusing the ",[17,18,22],"a",{"href":19,"rel":20},"https:\u002F\u002Fnssm.cc\u002F",[21],"nofollow","nssm"," utility.",[25,26,28],"h2",{"id":27},"why-run-the-device-agent-as-a-service","Why run the device agent as a service?",[10,30,31,32,36],{},"The standard process for running FlowFuse's device agent is to start it on the\ncommand line using the command ",[33,34,35],"code",{},"flowfuse-device-agent",". This works fine for testing\nbut for long-term installations it's useful to run the device agent as a service.\nOnce running as a service, the device agent will continue to run even if you\nlog off or the computer is restarted and no user is logged in.",[25,38,40],{"id":39},"summary","Summary",[10,42,43],{},"The aim of this how-to is to install the FlowFuse device-agent as a service on a Windows computer.",[10,45,46],{},"There will be two main parts to this:",[48,49,50,54],"ol",{},[51,52,53],"li",{},"Install the device-agent",[51,55,56],{},"Setup the device-agent to run as a Windows service",[10,58,59],{},"Additionally, two user accounts will be needed for this configuration:",[48,61,62,70],{},[51,63,64,65,69],{},"A ",[66,67,68],"strong",{},"user"," account that will be used to run the device-agent (typically, non-admin account)",[51,71,72,73,76],{},"An ",[66,74,75],{},"admin"," account that can run elevated commands and will be used to setup the service",[10,78,79,80,82,83],{},"We will create a directory for the device-agent files and set the permissions on that directory so that the ",[66,81,68],{}," account can read and write files in that directory.\n",[84,85,86,87],"em",{},"This will be ",[33,88,89],{},"c:\\opt\\flowfuse-device",[10,91,92,93,96],{},"To make the device-agent run as a service, we will (in this example), use ",[17,94,22],{"href":19,"rel":95},[21]," but you are free to choose an alternative tool to run the device agent as a service.",[10,98,99,100,103],{},"Finally, we set the service to run under the ",[66,101,102],{},"service"," account.",[10,105,106],{},[84,107,108,109],{},"NOTE: The instructions in this how to were written on ",[66,110,111],{},"Windows 11 Pro 22H2",[113,114,116],"h3",{"id":115},"tip-using-domain-accounts","TIP: Using domain accounts",[10,118,119,120,122,123,126,127,129],{},"If the account is a domain account, append the domain name to the ",[66,121,68],{}," e.g. ",[33,124,125],{},"user@domain"," whenever the ",[66,128,68],{}," name is used in the instructions below.",[113,131,133],{"id":132},"tip-launching-an-elevated-command-prompt-window-eg-as-the-admin-user","TIP: Launching an elevated command prompt window (e.g. as the admin user)",[135,136,141],"pre",{"className":137,"code":138,"language":139,"meta":140,"style":140},"language-bash shiki shiki-themes github-light github-dark","powershell -Command \"Start-Process 'cmd' -Verb runAs\n","bash","",[33,142,143],{"__ignoreMap":140},[144,145,148,152,156],"span",{"class":146,"line":147},"line",1,[144,149,151],{"class":150},"sScJk","powershell",[144,153,155],{"class":154},"sj4cs"," -Command",[144,157,159],{"class":158},"sZZnC"," \"Start-Process 'cmd' -Verb runAs\n",[113,161,163],{"id":162},"tip-launching-an-elevated-powershell-prompt-window-eg-as-the-admin-user","TIP: Launching an elevated powershell prompt window (e.g. as the admin user)",[135,165,167],{"className":137,"code":166,"language":139,"meta":140,"style":140},"powershell -Command \"Start-Process 'powershell' -Verb runAs\n",[33,168,169],{"__ignoreMap":140},[144,170,171,173,175],{"class":146,"line":147},[144,172,151],{"class":150},[144,174,155],{"class":154},[144,176,177],{"class":158}," \"Start-Process 'powershell' -Verb runAs\n",[25,179,181],{"id":180},"pre-requisites","Pre-requisites",[113,183,185],{"id":184},"install-nodejs","Install Node.js",[10,187,188,189,193],{},"The device-agent requires Node.js to be installed. You can download the latest version from ",[17,190,191],{"href":191,"rel":192},"https:\u002F\u002Fnodejs.org\u002Fen\u002Fdownload\u002F",[21],".",[10,195,196],{},"It is recommended to install the LTS version and to check the \"Automatically install the necessary tools\" option. This is especially important if you intend on using any nodes that require native modules (like serialport).",[113,198,200],{"id":199},"create-a-new-windows-user","Create a New Windows User",[10,202,203,204,206,207,193],{},"If you need to create a new ",[66,205,68],{}," account follow these ",[17,208,211],{"href":209,"rel":210},"https:\u002F\u002Fsupport.microsoft.com\u002Fen-us\u002Fwindows\u002Fcreate-a-local-user-or-administrator-account-in-windows-20de74e0-ac7f-3502-a866-32915af2a34d#:~:text=Select%20Start%20%3E%20Settings%20%3E%20Accounts%20and,other%20user%2C%20select%20Add%20account.",[21],"instructions",[25,213,215],{"id":214},"prepare-the-device-agent-files-directory","Prepare the device-agent files directory",[10,217,218,219,223],{},"As the admin user, open an ",[17,220,222],{"href":221},"#tip%3A-launching-an-elevated-command-prompt-window-(e.g.-as-the-admin-user)","elevated"," command prompt, create the files directory and setup access permissions.",[135,225,227],{"className":137,"code":226,"language":139,"meta":140,"style":140},"# In an elevated command prompt\nmkdir c:\\opt\nmkdir c:\\opt\\flowfuse-device\n# grant full access to the service account that will run the device-agent\nicacls c:\\opt\\flowfuse-device \u002Fgrant \"user\":F \u002FT\n",[33,228,229,235,250,268,274],{"__ignoreMap":140},[144,230,231],{"class":146,"line":147},[144,232,234],{"class":233},"sJ8bj","# In an elevated command prompt\n",[144,236,238,241,244,247],{"class":146,"line":237},2,[144,239,240],{"class":150},"mkdir",[144,242,243],{"class":158}," c:",[144,245,246],{"class":154},"\\o",[144,248,249],{"class":158},"pt\n",[144,251,253,255,257,259,262,265],{"class":146,"line":252},3,[144,254,240],{"class":150},[144,256,243],{"class":158},[144,258,246],{"class":154},[144,260,261],{"class":158},"pt",[144,263,264],{"class":154},"\\f",[144,266,267],{"class":158},"lowfuse-device\n",[144,269,271],{"class":146,"line":270},4,[144,272,273],{"class":233},"# grant full access to the service account that will run the device-agent\n",[144,275,277,280,282,284,286,288,291,294,297],{"class":146,"line":276},5,[144,278,279],{"class":150},"icacls",[144,281,243],{"class":158},[144,283,246],{"class":154},[144,285,261],{"class":158},[144,287,264],{"class":154},[144,289,290],{"class":158},"lowfuse-device",[144,292,293],{"class":158}," \u002Fgrant",[144,295,296],{"class":158}," \"user\":F",[144,298,299],{"class":158}," \u002FT\n",[10,301,302],{},[84,303,304,305,308],{},"where ",[33,306,307],{},"\"user\""," is the service account (not the admin account)",[25,310,312],{"id":311},"install-nssm","Install nssm",[10,314,315,317,318,321],{},[33,316,22],{}," can simply be downloaded and executed from any path.\nWe will download it to the ",[33,319,320],{},"c:\\opt"," directory, extract the files and copy the 64 bit version to the current directory.",[113,323,325,328,329,331],{"id":324},"cmd-version-elevated-command-prompt",[33,326,327],{},"cmd"," version ",[17,330,222],{"href":221}," command prompt",[135,333,335],{"className":137,"code":334,"language":139,"meta":140,"style":140},"# starting in the device-agent files directory\ncd c:\\opt\n# download the nssm zip file\ncurl -LJO https:\u002F\u002Fnssm.cc\u002Frelease\u002Fnssm-2.24.zip\n# extract the files\ntar -xf nssm-2.24.zip\n# copy the 64 bit version to the current directory\ncopy nssm-2.24\\win64\\nssm.exe .\n# clean up\ndel nssm-2.24.zip\nrmdir \u002Fs \u002Fq nssm-2.24\n",[33,336,337,342,353,358,369,374,386,392,416,422,430],{"__ignoreMap":140},[144,338,339],{"class":146,"line":147},[144,340,341],{"class":233},"# starting in the device-agent files directory\n",[144,343,344,347,349,351],{"class":146,"line":237},[144,345,346],{"class":154},"cd",[144,348,243],{"class":158},[144,350,246],{"class":154},[144,352,249],{"class":158},[144,354,355],{"class":146,"line":252},[144,356,357],{"class":233},"# download the nssm zip file\n",[144,359,360,363,366],{"class":146,"line":270},[144,361,362],{"class":150},"curl",[144,364,365],{"class":154}," -LJO",[144,367,368],{"class":158}," https:\u002F\u002Fnssm.cc\u002Frelease\u002Fnssm-2.24.zip\n",[144,370,371],{"class":146,"line":276},[144,372,373],{"class":233},"# extract the files\n",[144,375,377,380,383],{"class":146,"line":376},6,[144,378,379],{"class":150},"tar",[144,381,382],{"class":154}," -xf",[144,384,385],{"class":158}," nssm-2.24.zip\n",[144,387,389],{"class":146,"line":388},7,[144,390,391],{"class":233},"# copy the 64 bit version to the current directory\n",[144,393,395,398,401,404,407,410,413],{"class":146,"line":394},8,[144,396,397],{"class":150},"copy",[144,399,400],{"class":158}," nssm-2.24",[144,402,403],{"class":154},"\\w",[144,405,406],{"class":158},"in64",[144,408,409],{"class":154},"\\n",[144,411,412],{"class":158},"ssm.exe",[144,414,415],{"class":158}," .\n",[144,417,419],{"class":146,"line":418},9,[144,420,421],{"class":233},"# clean up\n",[144,423,425,428],{"class":146,"line":424},10,[144,426,427],{"class":150},"del",[144,429,385],{"class":158},[144,431,433,436,439,442],{"class":146,"line":432},11,[144,434,435],{"class":150},"rmdir",[144,437,438],{"class":158}," \u002Fs",[144,440,441],{"class":158}," \u002Fq",[144,443,444],{"class":158}," nssm-2.24\n",[113,446,448,328,450,453],{"id":447},"powershell-version-elevated-powershell-prompt",[33,449,151],{},[17,451,222],{"href":452},"#tip%3A-launching-an-elevated-powershell-prompt-window-(e.g.-as-the-admin-user)"," powershell prompt",[10,455,456,457,460],{},"If you don't have ",[33,458,459],{},"cURL"," installed, then powershell can be used to download the file. Here is how to do it:",[135,462,465],{"className":463,"code":464,"language":151,"meta":140,"style":140},"language-powershell shiki shiki-themes github-light github-dark","# starting in the device-agent files directory\ncd c:\\opt\n# download the nssm zip file\nInvoke-WebRequest -Uri https:\u002F\u002Fnssm.cc\u002Frelease\u002Fnssm-2.24.zip -OutFile nssm-2.24.zip\n# extract the files\nExpand-Archive -Path nssm-2.24.zip .\n# copy the 64 bit version to the current directory\nCopy-Item -Path .\\nssm-2.24\\win64\\nssm.exe -Destination .\n# clean up\nRemove-Item -Path nssm-2.24.zip\nRemove-Item -Path nssm-2.24 -Recurse\n",[33,466,467,471,476,480,485,489,494,498,503,507,512],{"__ignoreMap":140},[144,468,469],{"class":146,"line":147},[144,470,341],{},[144,472,473],{"class":146,"line":237},[144,474,475],{},"cd c:\\opt\n",[144,477,478],{"class":146,"line":252},[144,479,357],{},[144,481,482],{"class":146,"line":270},[144,483,484],{},"Invoke-WebRequest -Uri https:\u002F\u002Fnssm.cc\u002Frelease\u002Fnssm-2.24.zip -OutFile nssm-2.24.zip\n",[144,486,487],{"class":146,"line":276},[144,488,373],{},[144,490,491],{"class":146,"line":376},[144,492,493],{},"Expand-Archive -Path nssm-2.24.zip .\n",[144,495,496],{"class":146,"line":388},[144,497,391],{},[144,499,500],{"class":146,"line":394},[144,501,502],{},"Copy-Item -Path .\\nssm-2.24\\win64\\nssm.exe -Destination .\n",[144,504,505],{"class":146,"line":418},[144,506,421],{},[144,508,509],{"class":146,"line":424},[144,510,511],{},"Remove-Item -Path nssm-2.24.zip\n",[144,513,514],{"class":146,"line":432},[144,515,516],{},"Remove-Item -Path nssm-2.24 -Recurse\n",[113,518,520],{"id":519},"manual-download","Manual download",[10,522,523,524,528,529,531],{},"If you prefer, you can download the nssm zip file manually from ",[17,525,526],{"href":526,"rel":527},"https:\u002F\u002Fnssm.cc\u002Frelease\u002Fnssm-2.24.zip",[21]," and extract the files to the ",[33,530,320],{}," directory. Then copy the 64 bit version to the current directory.",[10,533,534,535,538,539,542],{},"Ultimately, you should end up with a file named ",[33,536,537],{},"nssm.exe"," in the ",[33,540,541],{},"c:\\opt\\"," directory.",[25,544,546],{"id":545},"install-and-configure-the-device-agent","Install and configure the device-agent",[10,548,549,550,552],{},"As the ",[66,551,102],{}," account, to do so open a command prompt window and run the following and authenticate:",[135,554,556],{"className":137,"code":555,"language":139,"meta":140,"style":140},"runas \u002Fuser:{serviceuser} cmd\n# e.g. runas \u002Fuser:winserv cmd\n",[33,557,558,569],{"__ignoreMap":140},[144,559,560,563,566],{"class":146,"line":147},[144,561,562],{"class":150},"runas",[144,564,565],{"class":158}," \u002Fuser:{serviceuser}",[144,567,568],{"class":158}," cmd\n",[144,570,571],{"class":146,"line":237},[144,572,573],{"class":233},"# e.g. runas \u002Fuser:winserv cmd\n",[10,575,576],{},[84,577,304,578,308],{},[33,579,580],{},"{serviceuser}",[113,582,584],{"id":583},"check-the-users-npm-global-path-is-set-in-the-users-environment-variables","Check the users npm global path is set in the Users Environment Variables",[10,586,587],{},"NOTE: The recommended flowfuse-device-agent instructions will result in the flowfuse-device-agent being installed in the NPM global directory.  And the instructions to launch the device-agent expect the NPM global directory to be in your user path.  This section will instruct you to a) find the NPM global path, then b) check the user’s path setting and, if necessary c) add the NPM global path to your user path.",[10,589,590],{},"First, make a note of the path currently set for npm global. You can do this by running the following command:",[135,592,594],{"className":137,"code":593,"language":139,"meta":140,"style":140},"npm config get prefix\n",[33,595,596],{"__ignoreMap":140},[144,597,598,601,604,607],{"class":146,"line":147},[144,599,600],{"class":150},"npm",[144,602,603],{"class":158}," config",[144,605,606],{"class":158}," get",[144,608,609],{"class":158}," prefix\n",[10,611,612,613,616,617,619,620,622],{},"Next, ensure the ",[33,614,615],{},"Path"," Variable under the \"User variables for ",[84,618,68],{},"\" contains the npm global path that we obtained in the previous step.\nUse the below command, to check the user’s ",[33,621,615],{}," setting.  If it is not present, edit the path to include it.",[135,624,626],{"className":137,"code":625,"language":139,"meta":140,"style":140},"# This commands opens the environment variables editor, \n# look for the \"Path\" variable under \"User variables for user\",\n# and ensure it contains the npm global path\nrundll32 sysdm.cpl,EditEnvironmentVariables\n",[33,627,628,633,638,643],{"__ignoreMap":140},[144,629,630],{"class":146,"line":147},[144,631,632],{"class":233},"# This commands opens the environment variables editor, \n",[144,634,635],{"class":146,"line":237},[144,636,637],{"class":233},"# look for the \"Path\" variable under \"User variables for user\",\n",[144,639,640],{"class":146,"line":252},[144,641,642],{"class":233},"# and ensure it contains the npm global path\n",[144,644,645,648],{"class":146,"line":270},[144,646,647],{"class":150},"rundll32",[144,649,650],{"class":158}," sysdm.cpl,EditEnvironmentVariables\n",[10,652,653,654,656,657,660,661,193],{},"If you did have to add the npm path to the users ",[33,655,615],{}," variable, you will need to ",[66,658,659],{},"restart"," the command prompt for the change to take effect and relogin as ",[66,662,68],{},[113,664,666],{"id":665},"install-the-device-agent","Install the device agent",[10,668,669,670,673],{},"Note: you may have already installed the device-agent, however, ",[66,671,672],{},"we strongly recommend"," you do this step again as the service account and ensure that account has the latest version.",[135,675,677],{"className":137,"code":676,"language":139,"meta":140,"style":140},"npm i -g @flowfuse\u002Fdevice-agent\n",[33,678,679],{"__ignoreMap":140},[144,680,681,683,686,689],{"class":146,"line":147},[144,682,600],{"class":150},[144,684,685],{"class":158}," i",[144,687,688],{"class":154}," -g",[144,690,691],{"class":158}," @flowfuse\u002Fdevice-agent\n",[113,693,695],{"id":694},"link-the-device-agent-to-your-flowfuse-team","Link the device-agent to your flowfuse team",[10,697,698],{},"First, we must run the device-agent and link it to our FlowFuse team.  This will generate a \"device configuration\" details that we will use to configure the device-agent.\nBelow is how to run the device-agent with the UI enabled.  This will allow you to configure the device-agent via its web UI.",[135,700,702],{"className":137,"code":701,"language":139,"meta":140,"style":140},"flowfuse-device-agent --ui --ui-port 8080 --ui-user admin --ui-pass admin -d c:\\opt\\flowfuse-device -p 1880\n",[33,703,704],{"__ignoreMap":140},[144,705,706,708,711,714,717,720,723,726,728,731,733,735,737,739,741,744],{"class":146,"line":147},[144,707,35],{"class":150},[144,709,710],{"class":154}," --ui",[144,712,713],{"class":154}," --ui-port",[144,715,716],{"class":154}," 8080",[144,718,719],{"class":154}," --ui-user",[144,721,722],{"class":158}," admin",[144,724,725],{"class":154}," --ui-pass",[144,727,722],{"class":158},[144,729,730],{"class":154}," -d",[144,732,243],{"class":158},[144,734,246],{"class":154},[144,736,261],{"class":158},[144,738,264],{"class":154},[144,740,290],{"class":158},[144,742,743],{"class":154}," -p",[144,745,746],{"class":154}," 1880\n",[10,748,749,750,754,755],{},"The device-agent will now be running and you can access the UI at ",[17,751,752],{"href":752,"rel":753},"http:\u002F\u002F127.0.0.1:8080",[21]," with the user and password both \"admin\" (you can change these in the command line if required).\n",[84,756,757],{},"NOTE: These credentials are temporary and only valid during the device setup",[10,759,760,761,765,766,769],{},"Proceed to configure the device-agent and link it to your flowfuse team. Full instructions can be found ",[17,762,764],{"href":763},"\u002Fdocs\u002Fdevice-agent\u002Fregister","here",".\nOnce you have linked the device-agent to your team, you can stop it by pressing ",[33,767,768],{},"ctrl+c"," in the command prompt window.",[25,771,773],{"id":772},"create-the-device-agent-service","Create the device-agent service",[10,775,776,777,780],{},"As the admin user, open an elevated command prompt see ",[17,778,779],{"href":221},"TIP"," above",[113,782,784],{"id":783},"install-device-agent-as-a-service","Install device-agent as a service",[135,786,788],{"className":137,"code":787,"language":139,"meta":140,"style":140},"cd c:\\opt\n.\\nssm.exe install flowfuse-device-agent \"flowfuse-device-agent.cmd\"\n.\\nssm.exe set flowfuse-device-agent AppDirectory \"c:\\opt\\flowfuse-device\"\n.\\nssm.exe set flowfuse-device-agent Description \"FlowFuse Device Agent\"\n# set the AppParameters (cli options) to tell the agent where its home directory is\n# in our case, this is c:\\opt\\flowfuse-device and is set with the -d option\n.\\nssm.exe set flowfuse-device-agent AppParameters \"-d c:\\opt\\flowfuse-device -p 1880\"\n",[33,789,790,800,819,838,856,861,866],{"__ignoreMap":140},[144,791,792,794,796,798],{"class":146,"line":147},[144,793,346],{"class":154},[144,795,243],{"class":158},[144,797,246],{"class":154},[144,799,249],{"class":158},[144,801,802,804,808,810,813,816],{"class":146,"line":237},[144,803,193],{"class":154},[144,805,807],{"class":806},"sVt8B","\\",[144,809,537],{"class":158},[144,811,812],{"class":158}," install",[144,814,815],{"class":158}," flowfuse-device-agent",[144,817,818],{"class":158}," \"flowfuse-device-agent.cmd\"\n",[144,820,821,823,825,827,830,832,835],{"class":146,"line":252},[144,822,193],{"class":154},[144,824,807],{"class":806},[144,826,537],{"class":158},[144,828,829],{"class":158}," set",[144,831,815],{"class":158},[144,833,834],{"class":158}," AppDirectory",[144,836,837],{"class":158}," \"c:\\opt\\flowfuse-device\"\n",[144,839,840,842,844,846,848,850,853],{"class":146,"line":270},[144,841,193],{"class":154},[144,843,807],{"class":806},[144,845,537],{"class":158},[144,847,829],{"class":158},[144,849,815],{"class":158},[144,851,852],{"class":158}," Description",[144,854,855],{"class":158}," \"FlowFuse Device Agent\"\n",[144,857,858],{"class":146,"line":276},[144,859,860],{"class":233},"# set the AppParameters (cli options) to tell the agent where its home directory is\n",[144,862,863],{"class":146,"line":376},[144,864,865],{"class":233},"# in our case, this is c:\\opt\\flowfuse-device and is set with the -d option\n",[144,867,868,870,872,874,876,878,881],{"class":146,"line":388},[144,869,193],{"class":154},[144,871,807],{"class":806},[144,873,537],{"class":158},[144,875,829],{"class":158},[144,877,815],{"class":158},[144,879,880],{"class":158}," AppParameters",[144,882,883],{"class":158}," \"-d c:\\opt\\flowfuse-device -p 1880\"\n",[113,885,887],{"id":886},"check-the-service-is-installed","Check the service is installed",[10,889,890],{},"Run the following command to check the service is installed:",[135,892,894],{"className":137,"code":893,"language":139,"meta":140,"style":140},"services.msc\n",[33,895,896],{"__ignoreMap":140},[144,897,898],{"class":146,"line":147},[144,899,893],{"class":150},[10,901,902],{},"(look for a service named `flowfuse-device-agent').",[10,904,905,906,909],{},"Alternatively, you can use the ",[33,907,908],{},"sc"," command:",[135,911,913],{"className":137,"code":912,"language":139,"meta":140,"style":140},"sc query flowfuse-device-agent\n",[33,914,915],{"__ignoreMap":140},[144,916,917,919,922],{"class":146,"line":147},[144,918,908],{"class":150},[144,920,921],{"class":158}," query",[144,923,924],{"class":158}," flowfuse-device-agent\n",[113,926,928],{"id":927},"set-the-user-account-that-will-run-the-service","Set the user account that will run the service",[10,930,931],{},"Some things are easier to edit in the UI, so we will edit the service via the NSSM UI.",[135,933,935],{"className":137,"code":934,"language":139,"meta":140,"style":140},"nssm edit flowfuse-device-agent\n",[33,936,937],{"__ignoreMap":140},[144,938,939,941,944],{"class":146,"line":147},[144,940,22],{"class":150},[144,942,943],{"class":158}," edit",[144,945,924],{"class":158},[10,947,948],{},[949,950],"img",{"alt":951,"src":952},"nssm editor","\u002Fblog\u002F2023\u002F12\u002Fimages\u002Fnssm_service_editor.png",[10,954,955,956,959],{},"In the UI, you can edit the service name, description, startup type, etc.\nThe most important thing to check is the ",[33,957,958],{},"Application"," tab. This includes the path to the flowfuse-device-agent.cmd and its arguments.\nSelect the \"Log on\" tab, select \"This account\" and enter the service account name and password that will run the device-agent.\nClick the \"Edit Service\" button to save the changes.",[10,961,962,963,965],{},"Now you have a service that will run the device-agent as the ",[66,964,102],{}," account 🎉",[113,967,969],{"id":968},"controlling-the-service","Controlling the service",[10,971,972],{},"You can start the service with the command:",[135,974,976],{"className":137,"code":975,"language":139,"meta":140,"style":140},"sc start flowfuse-device-agent\n",[33,977,978],{"__ignoreMap":140},[144,979,980,982,985],{"class":146,"line":147},[144,981,908],{"class":150},[144,983,984],{"class":158}," start",[144,986,924],{"class":158},[10,988,989],{},"You can check the current status with the command:",[135,991,992],{"className":137,"code":912,"language":139,"meta":140,"style":140},[33,993,994],{"__ignoreMap":140},[144,995,996,998,1000],{"class":146,"line":147},[144,997,908],{"class":150},[144,999,921],{"class":158},[144,1001,924],{"class":158},[10,1003,1004],{},"You can stop the service with the command:",[135,1006,1008],{"className":137,"code":1007,"language":139,"meta":140,"style":140},"sc stop flowfuse-device-agent\n",[33,1009,1010],{"__ignoreMap":140},[144,1011,1012,1014,1017],{"class":146,"line":147},[144,1013,908],{"class":150},[144,1015,1016],{"class":158}," stop",[144,1018,924],{"class":158},[113,1020,1022],{"id":1021},"further-reading","Further reading",[10,1024,1025,1026,1028,1029,1031],{},"If you'd like to learn about windows services via the ",[33,1027,908],{}," command you can access\nthe help text by running ",[33,1030,908],{}," from a command prompt.",[1033,1034,1035],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}",{"title":140,"searchDepth":237,"depth":237,"links":1037},[1038,1039,1044,1048,1049,1056,1061],{"id":27,"depth":237,"text":28},{"id":39,"depth":237,"text":40,"children":1040},[1041,1042,1043],{"id":115,"depth":252,"text":116},{"id":132,"depth":252,"text":133},{"id":162,"depth":252,"text":163},{"id":180,"depth":237,"text":181,"children":1045},[1046,1047],{"id":184,"depth":252,"text":185},{"id":199,"depth":252,"text":200},{"id":214,"depth":237,"text":215},{"id":311,"depth":237,"text":312,"children":1050},[1051,1053,1055],{"id":324,"depth":252,"text":1052},"cmd version elevated command prompt",{"id":447,"depth":252,"text":1054},"powershell version elevated powershell prompt",{"id":519,"depth":252,"text":520},{"id":545,"depth":237,"text":546,"children":1057},[1058,1059,1060],{"id":583,"depth":252,"text":584},{"id":665,"depth":252,"text":666},{"id":694,"depth":252,"text":695},{"id":772,"depth":237,"text":773,"children":1062},[1063,1064,1065,1066,1067],{"id":783,"depth":252,"text":784},{"id":886,"depth":252,"text":887},{"id":927,"depth":252,"text":928},{"id":968,"depth":252,"text":969},{"id":1021,"depth":252,"text":1022},"md",{"navTitle":5,"excerpt":1070},{"type":7,"value":1071},[1072,1074],[10,1073,12],{},[10,1075,15,1076,23],{},[17,1077,22],{"href":19,"rel":1078},[21],true,"\u002Fblog\u002F2023\u002F12\u002Fdevice-agent-as-a-windows-service",{"title":5,"description":12},"blog\u002F2023\u002F12\u002Fdevice-agent-as-a-windows-service","oF_JHnPZJ9Hc6Vlv8vmp_41MAO46GWRrCloqCc7sqDc",1780070551175]