@@ -62,7 +62,7 @@ var initCmd = &cobra.Command{
6262 var configDir , configPath string
6363
6464 if runtime .GOOS == "windows" {
65- configDir = filepath .Join (os .Getenv ("ProgramData " ), "updatectl" )
65+ configDir = filepath .Join (os .Getenv ("USERPROFILE " ), "updatectl" )
6666 } else {
6767 configDir = "/etc/updatectl"
6868 }
@@ -86,9 +86,45 @@ projects:
8686 }
8787
8888 if runtime .GOOS == "windows" {
89- taskCmd := `schtasks /Create /TN "updatectl" /TR "updatectl watch" /SC ONSTART /RL HIGHEST /F`
90- exec .Command ("cmd" , "/C" , taskCmd ).Run ()
89+ taskName := "updatectl"
90+ configDir := filepath .Join (os .Getenv ("USERPROFILE" ), "updatectl" )
91+
92+ batScript := fmt .Sprintf (`@echo off
93+ start "" /b "%s" watch
94+ ` , filepath .Join (configDir , "updatectl.exe" ))
95+ batScriptPath := filepath .Join (configDir , "run_updatectl.bat" )
96+
97+ err := os .WriteFile (batScriptPath , []byte (batScript ), 0644 )
98+ if err != nil {
99+ fmt .Println ("Failed to write batch wrapper script:" , err )
100+ return
101+ }
102+
103+ taskRun := batScriptPath
104+
105+ cmd := exec .Command (
106+ "schtasks" ,
107+ "/Create" ,
108+ "/TN" , taskName ,
109+ "/TR" , taskRun ,
110+ "/SC" , "ONSTART" ,
111+ "/RL" , "HIGHEST" ,
112+ "/F" ,
113+ )
114+ output , err := cmd .CombinedOutput ()
115+ if err != nil {
116+ fmt .Printf ("Failed to create scheduled task: %v\n Output: %s\n " , err , output )
117+ return
118+ }
91119 fmt .Println ("Created Windows Task Scheduler job for updatectl." )
120+
121+ runCmd := exec .Command ("schtasks" , "/Run" , "/TN" , taskName )
122+ runOutput , runErr := runCmd .CombinedOutput ()
123+ if runErr != nil {
124+ fmt .Printf ("Failed to run scheduled task immediately: %v\n Output: %s\n " , runErr , runOutput )
125+ } else {
126+ fmt .Println ("Scheduled task started immediately." )
127+ }
92128 } else {
93129 fmt .Print ("Enter the user for the systemd service (default: root): " )
94130 scanner := bufio .NewScanner (os .Stdin )
@@ -168,7 +204,7 @@ var buildCmd = &cobra.Command{
168204func loadConfig () Config {
169205 var configPath string
170206 if runtime .GOOS == "windows" {
171- configPath = filepath .Join (os .Getenv ("ProgramData " ), "updatectl" , "updatectl.yaml" )
207+ configPath = filepath .Join (os .Getenv ("USERPROFILE " ), "updatectl" , "updatectl.yaml" )
172208 } else {
173209 configPath = "/etc/updatectl/updatectl.yaml"
174210 }
0 commit comments